zkcloudworker 0.15.0 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NFTUpdateProof = exports.NFTImmutableState = exports.NFTState = exports.CollectionData = exports.NFTData = exports.MintSignatureData = exports.MintParams = exports.Storage = void 0;
4
+ const o1js_1 = require("o1js");
5
+ class Storage extends (0, o1js_1.Struct)({
6
+ url: o1js_1.Provable.Array(o1js_1.Field, 2),
7
+ }) {
8
+ constructor(value) {
9
+ super(value);
10
+ }
11
+ static assertEquals(a, b) {
12
+ a.url[0].assertEquals(b.url[0]);
13
+ a.url[1].assertEquals(b.url[1]);
14
+ }
15
+ static equals(a, b) {
16
+ return a.url[0].equals(b.url[0]).and(a.url[1].equals(b.url[1]));
17
+ }
18
+ static fromURL(url) {
19
+ const fields = o1js_1.Encoding.stringToFields(url);
20
+ if (fields.length !== 2)
21
+ throw new Error("Invalid URL");
22
+ return new Storage({ url: [fields[0], fields[1]] });
23
+ }
24
+ toURL() {
25
+ return o1js_1.Encoding.stringFromFields(this.url);
26
+ }
27
+ }
28
+ exports.Storage = Storage;
29
+ class NFTImmutableState extends (0, o1js_1.Struct)({
30
+ creator: o1js_1.PublicKey, // readonly
31
+ canChangeOwner: o1js_1.Bool, // readonly
32
+ canChangeMetadata: o1js_1.Bool, // readonly
33
+ canChangePrice: o1js_1.Bool, // readonly
34
+ canChangeStorage: o1js_1.Bool, // readonly
35
+ canChangeName: o1js_1.Bool, // readonly
36
+ canChangeMetadataVerificationKeyHash: o1js_1.Bool, // readonly
37
+ canPause: o1js_1.Bool, // readonly
38
+ address: o1js_1.PublicKey, // readonly
39
+ tokenId: o1js_1.Field, // readonly
40
+ }) {
41
+ static assertEqual(a, b) {
42
+ a.creator.assertEquals(b.creator);
43
+ a.canChangeOwner.assertEquals(b.canChangeOwner);
44
+ a.canChangeMetadata.assertEquals(b.canChangeMetadata);
45
+ a.canChangePrice.assertEquals(b.canChangePrice);
46
+ a.canChangeStorage.assertEquals(b.canChangeStorage);
47
+ a.canChangeName.assertEquals(b.canChangeName);
48
+ a.canChangeMetadataVerificationKeyHash.assertEquals(b.canChangeMetadataVerificationKeyHash);
49
+ a.canPause.assertEquals(b.canPause);
50
+ a.address.assertEquals(b.address);
51
+ a.tokenId.assertEquals(b.tokenId);
52
+ }
53
+ }
54
+ exports.NFTImmutableState = NFTImmutableState;
55
+ class NFTState extends (0, o1js_1.Struct)({
56
+ immutableState: NFTImmutableState,
57
+ name: o1js_1.Field,
58
+ metadata: o1js_1.Field,
59
+ storage: Storage,
60
+ owner: o1js_1.PublicKey,
61
+ price: o1js_1.UInt64,
62
+ version: o1js_1.UInt32,
63
+ isPaused: o1js_1.Bool,
64
+ }) {
65
+ static assertEqual(a, b) {
66
+ NFTImmutableState.assertEqual(a.immutableState, b.immutableState);
67
+ a.name.assertEquals(b.name);
68
+ a.metadata.assertEquals(b.metadata);
69
+ Storage.assertEquals(a.storage, b.storage);
70
+ a.owner.assertEquals(b.owner);
71
+ a.price.assertEquals(b.price);
72
+ a.version.assertEquals(b.version);
73
+ a.isPaused.assertEquals(b.isPaused);
74
+ }
75
+ }
76
+ exports.NFTState = NFTState;
77
+ class NFTUpdateProof extends o1js_1.DynamicProof {
78
+ }
79
+ exports.NFTUpdateProof = NFTUpdateProof;
80
+ NFTUpdateProof.publicInputType = NFTState;
81
+ NFTUpdateProof.publicOutputType = NFTState;
82
+ NFTUpdateProof.maxProofsVerified = 2;
83
+ NFTUpdateProof.featureFlags = o1js_1.FeatureFlags.allMaybe;
84
+ class NFTData extends (0, o1js_1.Struct)({
85
+ price: o1js_1.UInt64,
86
+ version: o1js_1.UInt32,
87
+ canChangeOwner: o1js_1.Bool, // readonly
88
+ canChangeMetadata: o1js_1.Bool, // readonly
89
+ canChangePrice: o1js_1.Bool, // readonly
90
+ canChangeStorage: o1js_1.Bool, // readonly
91
+ canChangeName: o1js_1.Bool, // readonly
92
+ canChangeMetadataVerificationKeyHash: o1js_1.Bool, // readonly
93
+ canPause: o1js_1.Bool, // readonly
94
+ isPaused: o1js_1.Bool,
95
+ // what else?
96
+ }) {
97
+ new(params = {}) {
98
+ const { price, version, canChangeOwner, canChangeMetadata, canChangePrice, canChangeStorage, canChangeName, canChangeMetadataVerificationKeyHash, canPause, isPaused, } = params;
99
+ return new NFTData({
100
+ price: o1js_1.UInt64.from(price ?? 0),
101
+ version: o1js_1.UInt32.from(version ?? 0),
102
+ canChangeOwner: (0, o1js_1.Bool)(canChangeOwner ?? true),
103
+ canChangeMetadata: (0, o1js_1.Bool)(canChangeMetadata ?? false),
104
+ canChangePrice: (0, o1js_1.Bool)(canChangePrice ?? true),
105
+ canChangeStorage: (0, o1js_1.Bool)(canChangeStorage ?? false),
106
+ canChangeName: (0, o1js_1.Bool)(canChangeName ?? false),
107
+ canChangeMetadataVerificationKeyHash: (0, o1js_1.Bool)(canChangeMetadataVerificationKeyHash ?? false),
108
+ canPause: (0, o1js_1.Bool)(canPause ?? false),
109
+ isPaused: (0, o1js_1.Bool)(isPaused ?? false),
110
+ });
111
+ }
112
+ pack() {
113
+ const price = this.price.value.toBits(64);
114
+ const version = this.version.value.toBits(32);
115
+ return o1js_1.Field.fromBits([
116
+ ...price,
117
+ ...version,
118
+ this.canChangeOwner,
119
+ this.canChangeMetadata,
120
+ this.canChangePrice,
121
+ this.canChangeStorage,
122
+ this.canChangeName,
123
+ this.canChangeMetadataVerificationKeyHash,
124
+ this.canPause,
125
+ this.isPaused,
126
+ ]);
127
+ }
128
+ static unpack(packed) {
129
+ const bits = packed.toBits(64 + 32 + 8);
130
+ const price = o1js_1.UInt64.Unsafe.fromField(o1js_1.Field.fromBits(bits.slice(0, 64)));
131
+ const version = o1js_1.UInt32.Unsafe.fromField(o1js_1.Field.fromBits(bits.slice(64, 64 + 32)));
132
+ const canChangeOwner = bits[64 + 32];
133
+ const canChangeMetadata = bits[64 + 32 + 1];
134
+ const canChangePrice = bits[64 + 32 + 2];
135
+ const canChangeStorage = bits[64 + 32 + 3];
136
+ const canChangeName = bits[64 + 32 + 4];
137
+ const canChangeMetadataVerificationKeyHash = bits[64 + 32 + 5];
138
+ const canPause = bits[64 + 32 + 6];
139
+ const isPaused = bits[64 + 32 + 7];
140
+ return new NFTData({
141
+ price,
142
+ version,
143
+ canChangeOwner,
144
+ canChangeMetadata,
145
+ canChangePrice,
146
+ canChangeStorage,
147
+ canChangeName,
148
+ canChangeMetadataVerificationKeyHash,
149
+ canPause,
150
+ isPaused,
151
+ });
152
+ }
153
+ }
154
+ exports.NFTData = NFTData;
155
+ class CollectionData extends (0, o1js_1.Struct)({
156
+ requireTransferApproval: o1js_1.Bool,
157
+ requireUpdateApproval: o1js_1.Bool,
158
+ requireSaleApproval: o1js_1.Bool,
159
+ requireBuyApproval: o1js_1.Bool,
160
+ requireMintApproval: o1js_1.Bool,
161
+ canMint: o1js_1.Bool,
162
+ canPause: o1js_1.Bool,
163
+ canResume: o1js_1.Bool,
164
+ canChangeName: o1js_1.Bool,
165
+ canChangeCreator: o1js_1.Bool,
166
+ canChangeBaseUri: o1js_1.Bool,
167
+ canChangeSaleCommission: o1js_1.Bool,
168
+ isPaused: o1js_1.Bool,
169
+ }) {
170
+ pack() {
171
+ return o1js_1.Field.fromBits([
172
+ this.requireTransferApproval,
173
+ this.requireUpdateApproval,
174
+ this.requireSaleApproval,
175
+ this.requireMintApproval,
176
+ this.requireBuyApproval,
177
+ this.canMint,
178
+ this.canChangeName,
179
+ this.canChangeCreator,
180
+ this.canChangeBaseUri,
181
+ this.canChangeSaleCommission,
182
+ this.canPause,
183
+ this.canResume,
184
+ this.isPaused,
185
+ ]);
186
+ }
187
+ static unpack(packed) {
188
+ const bits = packed.toBits(13);
189
+ return new CollectionData({
190
+ requireTransferApproval: bits[0],
191
+ requireUpdateApproval: bits[1],
192
+ requireSaleApproval: bits[2],
193
+ requireMintApproval: bits[3],
194
+ requireBuyApproval: bits[4],
195
+ canMint: bits[5],
196
+ canChangeName: bits[6],
197
+ canChangeCreator: bits[7],
198
+ canChangeBaseUri: bits[8],
199
+ canChangeSaleCommission: bits[9],
200
+ canPause: bits[10],
201
+ canResume: bits[11],
202
+ isPaused: bits[12],
203
+ });
204
+ }
205
+ }
206
+ exports.CollectionData = CollectionData;
207
+ class MintParams extends (0, o1js_1.Struct)({
208
+ name: o1js_1.Field,
209
+ address: o1js_1.PublicKey,
210
+ tokenId: o1js_1.Field,
211
+ owner: o1js_1.PublicKey,
212
+ data: NFTData,
213
+ fee: o1js_1.UInt64,
214
+ metadata: o1js_1.Field,
215
+ storage: Storage,
216
+ metadataVerificationKey: o1js_1.VerificationKey,
217
+ nftVerificationKey: o1js_1.VerificationKey,
218
+ expiry: o1js_1.UInt32,
219
+ }) {
220
+ }
221
+ exports.MintParams = MintParams;
222
+ class MintSignatureData extends (0, o1js_1.Struct)({
223
+ name: o1js_1.Field,
224
+ address: o1js_1.PublicKey,
225
+ tokenId: o1js_1.Field,
226
+ owner: o1js_1.PublicKey,
227
+ packedData: o1js_1.Field,
228
+ fee: o1js_1.UInt64,
229
+ metadata: o1js_1.Field,
230
+ storage: Storage,
231
+ metadataVerificationKeyHash: o1js_1.Field,
232
+ nftVerificationKeyHash: o1js_1.Field,
233
+ expiry: o1js_1.UInt32,
234
+ }) {
235
+ }
236
+ exports.MintSignatureData = MintSignatureData;
@@ -0,0 +1,21 @@
1
+ import { DeployArgs, PublicKey, SmartContract, State, VerificationKey, UInt64, Field } from "o1js";
2
+ import { MintParams, NFTState, NFTAdminBase, Storage } from "./types";
3
+ export interface NFTWhitelistedAdminDeployProps extends Exclude<DeployArgs, undefined> {
4
+ admin: PublicKey;
5
+ whitelist: Field;
6
+ storage: Storage;
7
+ }
8
+ export declare class NFTWhitelistedAdmin extends SmartContract implements NFTAdminBase {
9
+ admin: State<PublicKey>;
10
+ whitelist: State<import("o1js/dist/node/lib/provable/field").Field>;
11
+ storage: State<Storage>;
12
+ deploy(props: NFTWhitelistedAdminDeployProps): Promise<void>;
13
+ isWhitelisted(address: PublicKey, amount: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
14
+ updateVerificationKey(vk: VerificationKey): Promise<void>;
15
+ canMint(params: MintParams): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
16
+ canUpdate(input: NFTState, output: NFTState): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
17
+ canTransfer(address: PublicKey, from: PublicKey, to: PublicKey): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
18
+ canSell(address: PublicKey, seller: PublicKey, price: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
19
+ canBuy(address: PublicKey, seller: PublicKey, buyer: PublicKey, price: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
20
+ updateMerkleMapRoot(root: Field): Promise<void>;
21
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NFTWhitelistedAdmin = void 0;
13
+ const o1js_1 = require("o1js");
14
+ const whitelist_1 = require("./whitelist");
15
+ const types_1 = require("./types");
16
+ class NFTWhitelistedAdmin extends o1js_1.SmartContract {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.admin = (0, o1js_1.State)();
20
+ this.whitelist = (0, o1js_1.State)();
21
+ this.storage = (0, o1js_1.State)();
22
+ }
23
+ async deploy(props) {
24
+ await super.deploy(props);
25
+ this.admin.set(props.admin);
26
+ this.whitelist.set(props.whitelist);
27
+ this.storage.set(props.storage);
28
+ this.account.permissions.set({
29
+ ...o1js_1.Permissions.default(),
30
+ setVerificationKey: o1js_1.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
31
+ setPermissions: o1js_1.Permissions.impossible(),
32
+ });
33
+ }
34
+ async isWhitelisted(address, amount) {
35
+ const whitelist = this.whitelist.getAndRequireEquals();
36
+ const storage = this.storage.getAndRequireEquals();
37
+ const map = await o1js_1.Provable.witnessAsync(whitelist_1.Whitelist, async () => {
38
+ return await (0, whitelist_1.loadWhitelist)(storage);
39
+ });
40
+ map.root.assertEquals(whitelist);
41
+ const key = o1js_1.Poseidon.hash(address.toFields());
42
+ map.assertIncluded(key, "Address not whitelisted");
43
+ const value = map.get(key);
44
+ value.assertLessThanOrEqual((0, o1js_1.Field)(o1js_1.UInt64.MAXINT().value));
45
+ const maxAmount = o1js_1.UInt64.Unsafe.fromField(value);
46
+ return (0, o1js_1.Bool)(amount.lessThanOrEqual(maxAmount));
47
+ }
48
+ async updateVerificationKey(vk) {
49
+ const sender = this.sender.getAndRequireSignature();
50
+ this.admin.getAndRequireEquals().assertEquals(sender);
51
+ this.account.verificationKey.set(vk);
52
+ }
53
+ async canMint(params) {
54
+ return await this.isWhitelisted(params.owner, o1js_1.UInt64.from(0));
55
+ }
56
+ async canUpdate(input, output) {
57
+ return await this.isWhitelisted(output.owner, o1js_1.UInt64.from(0));
58
+ }
59
+ async canTransfer(address, from, to) {
60
+ return await this.isWhitelisted(to, o1js_1.UInt64.from(0));
61
+ }
62
+ async canSell(address, seller, price) {
63
+ return await this.isWhitelisted(address, price);
64
+ }
65
+ async canBuy(address, seller, buyer, price) {
66
+ return (await this.isWhitelisted(buyer, price)).and(await this.isWhitelisted(seller, price));
67
+ }
68
+ async updateMerkleMapRoot(root) {
69
+ const sender = this.sender.getAndRequireSignature();
70
+ this.admin.getAndRequireEquals().assertEquals(sender);
71
+ this.whitelist.set(root);
72
+ }
73
+ }
74
+ exports.NFTWhitelistedAdmin = NFTWhitelistedAdmin;
75
+ __decorate([
76
+ (0, o1js_1.state)(o1js_1.PublicKey),
77
+ __metadata("design:type", Object)
78
+ ], NFTWhitelistedAdmin.prototype, "admin", void 0);
79
+ __decorate([
80
+ (0, o1js_1.state)(o1js_1.Field),
81
+ __metadata("design:type", Object)
82
+ ], NFTWhitelistedAdmin.prototype, "whitelist", void 0);
83
+ __decorate([
84
+ (0, o1js_1.state)(types_1.Storage),
85
+ __metadata("design:type", Object)
86
+ ], NFTWhitelistedAdmin.prototype, "storage", void 0);
87
+ __decorate([
88
+ o1js_1.method,
89
+ __metadata("design:type", Function),
90
+ __metadata("design:paramtypes", [o1js_1.VerificationKey]),
91
+ __metadata("design:returntype", Promise)
92
+ ], NFTWhitelistedAdmin.prototype, "updateVerificationKey", null);
93
+ __decorate([
94
+ o1js_1.method.returns(o1js_1.Bool),
95
+ __metadata("design:type", Function),
96
+ __metadata("design:paramtypes", [types_1.MintParams]),
97
+ __metadata("design:returntype", Promise)
98
+ ], NFTWhitelistedAdmin.prototype, "canMint", null);
99
+ __decorate([
100
+ o1js_1.method.returns(o1js_1.Bool),
101
+ __metadata("design:type", Function),
102
+ __metadata("design:paramtypes", [types_1.NFTState, types_1.NFTState]),
103
+ __metadata("design:returntype", Promise)
104
+ ], NFTWhitelistedAdmin.prototype, "canUpdate", null);
105
+ __decorate([
106
+ o1js_1.method.returns(o1js_1.Bool),
107
+ __metadata("design:type", Function),
108
+ __metadata("design:paramtypes", [o1js_1.PublicKey, o1js_1.PublicKey, o1js_1.PublicKey]),
109
+ __metadata("design:returntype", Promise)
110
+ ], NFTWhitelistedAdmin.prototype, "canTransfer", null);
111
+ __decorate([
112
+ o1js_1.method.returns(o1js_1.Bool),
113
+ __metadata("design:type", Function),
114
+ __metadata("design:paramtypes", [o1js_1.PublicKey, o1js_1.PublicKey, o1js_1.UInt64]),
115
+ __metadata("design:returntype", Promise)
116
+ ], NFTWhitelistedAdmin.prototype, "canSell", null);
117
+ __decorate([
118
+ o1js_1.method.returns(o1js_1.Bool),
119
+ __metadata("design:type", Function),
120
+ __metadata("design:paramtypes", [o1js_1.PublicKey,
121
+ o1js_1.PublicKey,
122
+ o1js_1.PublicKey,
123
+ o1js_1.UInt64]),
124
+ __metadata("design:returntype", Promise)
125
+ ], NFTWhitelistedAdmin.prototype, "canBuy", null);
126
+ __decorate([
127
+ o1js_1.method,
128
+ __metadata("design:type", Function),
129
+ __metadata("design:paramtypes", [o1js_1.Field]),
130
+ __metadata("design:returntype", Promise)
131
+ ], NFTWhitelistedAdmin.prototype, "updateMerkleMapRoot", null);
@@ -0,0 +1,20 @@
1
+ import { Storage } from "./types";
2
+ declare const IndexedMerkleMap: typeof import("o1js/dist/node/lib/provable/merkle-tree-indexed").IndexedMerkleMap;
3
+ declare const Whitelist_base: typeof import("o1js/dist/node/lib/provable/merkle-tree-indexed").IndexedMerkleMapBase;
4
+ export declare class Whitelist extends Whitelist_base {
5
+ }
6
+ export declare function loadWhitelist(storage: Storage): Promise<Whitelist>;
7
+ interface IndexedMapSerialized {
8
+ height: number;
9
+ root: string;
10
+ length: string;
11
+ nodes: string;
12
+ sortedLeaves: string;
13
+ }
14
+ export declare function serializeWhitelist(map: Whitelist): string;
15
+ export declare function deserializeWhitelist(params: {
16
+ serializedIndexedMap: string;
17
+ type?: ReturnType<typeof IndexedMerkleMap>;
18
+ }): InstanceType<ReturnType<typeof IndexedMerkleMap>> | undefined;
19
+ export declare function parseIndexedMapSerialized(serializedMap: string): IndexedMapSerialized;
20
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Whitelist = void 0;
4
+ exports.loadWhitelist = loadWhitelist;
5
+ exports.serializeWhitelist = serializeWhitelist;
6
+ exports.deserializeWhitelist = deserializeWhitelist;
7
+ exports.parseIndexedMapSerialized = parseIndexedMapSerialized;
8
+ const o1js_1 = require("o1js");
9
+ const cloud_1 = require("../../cloud");
10
+ const { IndexedMerkleMap } = o1js_1.Experimental;
11
+ class Whitelist extends IndexedMerkleMap(10) {
12
+ }
13
+ exports.Whitelist = Whitelist;
14
+ async function loadWhitelist(storage) {
15
+ const url = "https://gateway.pinata.cloud/ipfs/" + storage.toURL();
16
+ const response = await fetch(url);
17
+ if (!response.ok) {
18
+ throw new Error("Failed to fetch whitelist");
19
+ }
20
+ const json = await response.text();
21
+ const map = deserializeWhitelist({
22
+ serializedIndexedMap: json,
23
+ type: Whitelist,
24
+ });
25
+ if (!map) {
26
+ throw new Error("Failed to deserialize whitelist");
27
+ }
28
+ return map;
29
+ }
30
+ function serializeWhitelist(map) {
31
+ const serializedMap = JSON.stringify({
32
+ height: map.height,
33
+ root: map.root.toJSON(),
34
+ length: map.length.toJSON(),
35
+ nodes: JSON.stringify(map.data.get().nodes, (_, v) => typeof v === "bigint" ? "n" + (0, cloud_1.bigintToBase64)(v) : v),
36
+ sortedLeaves: JSON.stringify(map.data
37
+ .get()
38
+ .sortedLeaves.map((v) => [
39
+ (0, cloud_1.bigintToBase64)(v.key),
40
+ (0, cloud_1.bigintToBase64)(v.nextKey),
41
+ (0, cloud_1.bigintToBase64)(v.value),
42
+ (0, cloud_1.bigintToBase64)(BigInt(v.index)),
43
+ ])),
44
+ }, null, 2);
45
+ return serializedMap;
46
+ }
47
+ function deserializeWhitelist(params) {
48
+ try {
49
+ const { serializedIndexedMap, type } = params;
50
+ const json = parseIndexedMapSerialized(serializedIndexedMap);
51
+ return deserializeIndexedMapInternal({
52
+ json,
53
+ type: type ?? IndexedMerkleMap(json.height),
54
+ });
55
+ }
56
+ catch (error) {
57
+ console.error("Error deserializing map:", error?.message ?? error);
58
+ return undefined;
59
+ }
60
+ }
61
+ function parseIndexedMapSerialized(serializedMap) {
62
+ const json = JSON.parse(serializedMap);
63
+ if (json.height === undefined ||
64
+ json.root === undefined ||
65
+ json.length === undefined ||
66
+ json.nodes === undefined ||
67
+ json.sortedLeaves === undefined)
68
+ throw new Error("wrong IndexedMerkleMap json format");
69
+ if (typeof json.height !== "number")
70
+ throw new Error("wrong IndexedMerkleMap height format");
71
+ if (typeof json.root !== "string")
72
+ throw new Error("wrong IndexedMerkleMap root format");
73
+ if (typeof json.length !== "string")
74
+ throw new Error("wrong IndexedMerkleMap length format");
75
+ if (typeof json.nodes !== "string")
76
+ throw new Error("wrong IndexedMerkleMap nodes format");
77
+ if (typeof json.sortedLeaves !== "string")
78
+ throw new Error("wrong IndexedMerkleMap sortedLeaves format");
79
+ return json;
80
+ }
81
+ function deserializeIndexedMapInternal(params) {
82
+ const { json, type } = params;
83
+ const map = new type();
84
+ if (json.height !== map.height) {
85
+ throw new Error("wrong IndexedMap height");
86
+ }
87
+ const nodes = JSON.parse(json.nodes, (_, v) => {
88
+ // Check if the value is a string that represents a BigInt
89
+ if (typeof v === "string" && v[0] === "n") {
90
+ // Remove the first 'n' and convert the string to a BigInt
91
+ return (0, cloud_1.bigintFromBase64)(v.slice(1));
92
+ }
93
+ return v;
94
+ });
95
+ const sortedLeaves = JSON.parse(json.sortedLeaves).map((row) => {
96
+ return {
97
+ key: (0, cloud_1.bigintFromBase64)(row[0]),
98
+ nextKey: (0, cloud_1.bigintFromBase64)(row[1]),
99
+ value: (0, cloud_1.bigintFromBase64)(row[2]),
100
+ index: Number((0, cloud_1.bigintFromBase64)(row[3])),
101
+ };
102
+ });
103
+ map.root = o1js_1.Field.fromJSON(json.root);
104
+ map.length = o1js_1.Field.fromJSON(json.length);
105
+ map.data.updateAsProver(() => {
106
+ return {
107
+ nodes: nodes.map((row) => [...row]),
108
+ sortedLeaves: [...sortedLeaves],
109
+ };
110
+ });
111
+ return map;
112
+ }