zkcloudworker 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ts/src/mina/index.d.ts +1 -0
- package/lib/ts/src/mina/index.js +1 -0
- package/lib/ts/src/mina/nft/index.d.ts +3 -0
- package/lib/ts/src/mina/nft/index.js +19 -0
- package/lib/ts/src/mina/nft/types.d.ts +1254 -0
- package/lib/ts/src/mina/nft/types.js +236 -0
- package/lib/ts/src/mina/nft/whitelist-admin.d.ts +21 -0
- package/lib/ts/src/mina/nft/whitelist-admin.js +131 -0
- package/lib/ts/src/mina/nft/whitelist.d.ts +20 -0
- package/lib/ts/src/mina/nft/whitelist.js +113 -0
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/mina/index.d.ts +1 -0
- package/lib/web/src/mina/index.js +1 -0
- package/lib/web/src/mina/index.js.map +1 -1
- package/lib/web/src/mina/nft/index.d.ts +3 -0
- package/lib/web/src/mina/nft/index.js +4 -0
- package/lib/web/src/mina/nft/index.js.map +1 -0
- package/lib/web/src/mina/nft/types.d.ts +1254 -0
- package/lib/web/src/mina/nft/types.js +227 -0
- package/lib/web/src/mina/nft/types.js.map +1 -0
- package/lib/web/src/mina/nft/whitelist-admin.d.ts +21 -0
- package/lib/web/src/mina/nft/whitelist-admin.js +120 -0
- package/lib/web/src/mina/nft/whitelist-admin.js.map +1 -0
- package/lib/web/src/mina/nft/whitelist.d.ts +20 -0
- package/lib/web/src/mina/nft/whitelist.js +106 -0
- package/lib/web/src/mina/nft/whitelist.js.map +1 -0
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -0,0 +1,227 @@
|
|
1
|
+
import { Field, PublicKey, Bool, VerificationKey, Struct, UInt32, UInt64, Encoding, Provable, DynamicProof, FeatureFlags, } from "o1js";
|
2
|
+
export { Storage, MintParams, MintSignatureData, NFTData, CollectionData, NFTState, NFTImmutableState, NFTUpdateProof, };
|
3
|
+
class Storage extends Struct({
|
4
|
+
url: Provable.Array(Field, 2),
|
5
|
+
}) {
|
6
|
+
constructor(value) {
|
7
|
+
super(value);
|
8
|
+
}
|
9
|
+
static assertEquals(a, b) {
|
10
|
+
a.url[0].assertEquals(b.url[0]);
|
11
|
+
a.url[1].assertEquals(b.url[1]);
|
12
|
+
}
|
13
|
+
static equals(a, b) {
|
14
|
+
return a.url[0].equals(b.url[0]).and(a.url[1].equals(b.url[1]));
|
15
|
+
}
|
16
|
+
static fromURL(url) {
|
17
|
+
const fields = Encoding.stringToFields(url);
|
18
|
+
if (fields.length !== 2)
|
19
|
+
throw new Error("Invalid URL");
|
20
|
+
return new Storage({ url: [fields[0], fields[1]] });
|
21
|
+
}
|
22
|
+
toURL() {
|
23
|
+
return Encoding.stringFromFields(this.url);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
class NFTImmutableState extends Struct({
|
27
|
+
creator: PublicKey, // readonly
|
28
|
+
canChangeOwner: Bool, // readonly
|
29
|
+
canChangeMetadata: Bool, // readonly
|
30
|
+
canChangePrice: Bool, // readonly
|
31
|
+
canChangeStorage: Bool, // readonly
|
32
|
+
canChangeName: Bool, // readonly
|
33
|
+
canChangeMetadataVerificationKeyHash: Bool, // readonly
|
34
|
+
canPause: Bool, // readonly
|
35
|
+
address: PublicKey, // readonly
|
36
|
+
tokenId: Field, // readonly
|
37
|
+
}) {
|
38
|
+
static assertEqual(a, b) {
|
39
|
+
a.creator.assertEquals(b.creator);
|
40
|
+
a.canChangeOwner.assertEquals(b.canChangeOwner);
|
41
|
+
a.canChangeMetadata.assertEquals(b.canChangeMetadata);
|
42
|
+
a.canChangePrice.assertEquals(b.canChangePrice);
|
43
|
+
a.canChangeStorage.assertEquals(b.canChangeStorage);
|
44
|
+
a.canChangeName.assertEquals(b.canChangeName);
|
45
|
+
a.canChangeMetadataVerificationKeyHash.assertEquals(b.canChangeMetadataVerificationKeyHash);
|
46
|
+
a.canPause.assertEquals(b.canPause);
|
47
|
+
a.address.assertEquals(b.address);
|
48
|
+
a.tokenId.assertEquals(b.tokenId);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
class NFTState extends Struct({
|
52
|
+
immutableState: NFTImmutableState,
|
53
|
+
name: Field,
|
54
|
+
metadata: Field,
|
55
|
+
storage: Storage,
|
56
|
+
owner: PublicKey,
|
57
|
+
price: UInt64,
|
58
|
+
version: UInt32,
|
59
|
+
isPaused: Bool,
|
60
|
+
}) {
|
61
|
+
static assertEqual(a, b) {
|
62
|
+
NFTImmutableState.assertEqual(a.immutableState, b.immutableState);
|
63
|
+
a.name.assertEquals(b.name);
|
64
|
+
a.metadata.assertEquals(b.metadata);
|
65
|
+
Storage.assertEquals(a.storage, b.storage);
|
66
|
+
a.owner.assertEquals(b.owner);
|
67
|
+
a.price.assertEquals(b.price);
|
68
|
+
a.version.assertEquals(b.version);
|
69
|
+
a.isPaused.assertEquals(b.isPaused);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
class NFTUpdateProof extends DynamicProof {
|
73
|
+
}
|
74
|
+
NFTUpdateProof.publicInputType = NFTState;
|
75
|
+
NFTUpdateProof.publicOutputType = NFTState;
|
76
|
+
NFTUpdateProof.maxProofsVerified = 2;
|
77
|
+
NFTUpdateProof.featureFlags = FeatureFlags.allMaybe;
|
78
|
+
class NFTData extends Struct({
|
79
|
+
price: UInt64,
|
80
|
+
version: UInt32,
|
81
|
+
canChangeOwner: Bool, // readonly
|
82
|
+
canChangeMetadata: Bool, // readonly
|
83
|
+
canChangePrice: Bool, // readonly
|
84
|
+
canChangeStorage: Bool, // readonly
|
85
|
+
canChangeName: Bool, // readonly
|
86
|
+
canChangeMetadataVerificationKeyHash: Bool, // readonly
|
87
|
+
canPause: Bool, // readonly
|
88
|
+
isPaused: Bool,
|
89
|
+
// what else?
|
90
|
+
}) {
|
91
|
+
new(params = {}) {
|
92
|
+
const { price, version, canChangeOwner, canChangeMetadata, canChangePrice, canChangeStorage, canChangeName, canChangeMetadataVerificationKeyHash, canPause, isPaused, } = params;
|
93
|
+
return new NFTData({
|
94
|
+
price: UInt64.from(price ?? 0),
|
95
|
+
version: UInt32.from(version ?? 0),
|
96
|
+
canChangeOwner: Bool(canChangeOwner ?? true),
|
97
|
+
canChangeMetadata: Bool(canChangeMetadata ?? false),
|
98
|
+
canChangePrice: Bool(canChangePrice ?? true),
|
99
|
+
canChangeStorage: Bool(canChangeStorage ?? false),
|
100
|
+
canChangeName: Bool(canChangeName ?? false),
|
101
|
+
canChangeMetadataVerificationKeyHash: Bool(canChangeMetadataVerificationKeyHash ?? false),
|
102
|
+
canPause: Bool(canPause ?? false),
|
103
|
+
isPaused: Bool(isPaused ?? false),
|
104
|
+
});
|
105
|
+
}
|
106
|
+
pack() {
|
107
|
+
const price = this.price.value.toBits(64);
|
108
|
+
const version = this.version.value.toBits(32);
|
109
|
+
return Field.fromBits([
|
110
|
+
...price,
|
111
|
+
...version,
|
112
|
+
this.canChangeOwner,
|
113
|
+
this.canChangeMetadata,
|
114
|
+
this.canChangePrice,
|
115
|
+
this.canChangeStorage,
|
116
|
+
this.canChangeName,
|
117
|
+
this.canChangeMetadataVerificationKeyHash,
|
118
|
+
this.canPause,
|
119
|
+
this.isPaused,
|
120
|
+
]);
|
121
|
+
}
|
122
|
+
static unpack(packed) {
|
123
|
+
const bits = packed.toBits(64 + 32 + 8);
|
124
|
+
const price = UInt64.Unsafe.fromField(Field.fromBits(bits.slice(0, 64)));
|
125
|
+
const version = UInt32.Unsafe.fromField(Field.fromBits(bits.slice(64, 64 + 32)));
|
126
|
+
const canChangeOwner = bits[64 + 32];
|
127
|
+
const canChangeMetadata = bits[64 + 32 + 1];
|
128
|
+
const canChangePrice = bits[64 + 32 + 2];
|
129
|
+
const canChangeStorage = bits[64 + 32 + 3];
|
130
|
+
const canChangeName = bits[64 + 32 + 4];
|
131
|
+
const canChangeMetadataVerificationKeyHash = bits[64 + 32 + 5];
|
132
|
+
const canPause = bits[64 + 32 + 6];
|
133
|
+
const isPaused = bits[64 + 32 + 7];
|
134
|
+
return new NFTData({
|
135
|
+
price,
|
136
|
+
version,
|
137
|
+
canChangeOwner,
|
138
|
+
canChangeMetadata,
|
139
|
+
canChangePrice,
|
140
|
+
canChangeStorage,
|
141
|
+
canChangeName,
|
142
|
+
canChangeMetadataVerificationKeyHash,
|
143
|
+
canPause,
|
144
|
+
isPaused,
|
145
|
+
});
|
146
|
+
}
|
147
|
+
}
|
148
|
+
class CollectionData extends Struct({
|
149
|
+
requireTransferApproval: Bool,
|
150
|
+
requireUpdateApproval: Bool,
|
151
|
+
requireSaleApproval: Bool,
|
152
|
+
requireBuyApproval: Bool,
|
153
|
+
requireMintApproval: Bool,
|
154
|
+
canMint: Bool,
|
155
|
+
canPause: Bool,
|
156
|
+
canResume: Bool,
|
157
|
+
canChangeName: Bool,
|
158
|
+
canChangeCreator: Bool,
|
159
|
+
canChangeBaseUri: Bool,
|
160
|
+
canChangeSaleCommission: Bool,
|
161
|
+
isPaused: Bool,
|
162
|
+
}) {
|
163
|
+
pack() {
|
164
|
+
return Field.fromBits([
|
165
|
+
this.requireTransferApproval,
|
166
|
+
this.requireUpdateApproval,
|
167
|
+
this.requireSaleApproval,
|
168
|
+
this.requireMintApproval,
|
169
|
+
this.requireBuyApproval,
|
170
|
+
this.canMint,
|
171
|
+
this.canChangeName,
|
172
|
+
this.canChangeCreator,
|
173
|
+
this.canChangeBaseUri,
|
174
|
+
this.canChangeSaleCommission,
|
175
|
+
this.canPause,
|
176
|
+
this.canResume,
|
177
|
+
this.isPaused,
|
178
|
+
]);
|
179
|
+
}
|
180
|
+
static unpack(packed) {
|
181
|
+
const bits = packed.toBits(13);
|
182
|
+
return new CollectionData({
|
183
|
+
requireTransferApproval: bits[0],
|
184
|
+
requireUpdateApproval: bits[1],
|
185
|
+
requireSaleApproval: bits[2],
|
186
|
+
requireMintApproval: bits[3],
|
187
|
+
requireBuyApproval: bits[4],
|
188
|
+
canMint: bits[5],
|
189
|
+
canChangeName: bits[6],
|
190
|
+
canChangeCreator: bits[7],
|
191
|
+
canChangeBaseUri: bits[8],
|
192
|
+
canChangeSaleCommission: bits[9],
|
193
|
+
canPause: bits[10],
|
194
|
+
canResume: bits[11],
|
195
|
+
isPaused: bits[12],
|
196
|
+
});
|
197
|
+
}
|
198
|
+
}
|
199
|
+
class MintParams extends Struct({
|
200
|
+
name: Field,
|
201
|
+
address: PublicKey,
|
202
|
+
tokenId: Field,
|
203
|
+
owner: PublicKey,
|
204
|
+
data: NFTData,
|
205
|
+
fee: UInt64,
|
206
|
+
metadata: Field,
|
207
|
+
storage: Storage,
|
208
|
+
metadataVerificationKey: VerificationKey,
|
209
|
+
nftVerificationKey: VerificationKey,
|
210
|
+
expiry: UInt32,
|
211
|
+
}) {
|
212
|
+
}
|
213
|
+
class MintSignatureData extends Struct({
|
214
|
+
name: Field,
|
215
|
+
address: PublicKey,
|
216
|
+
tokenId: Field,
|
217
|
+
owner: PublicKey,
|
218
|
+
packedData: Field,
|
219
|
+
fee: UInt64,
|
220
|
+
metadata: Field,
|
221
|
+
storage: Storage,
|
222
|
+
metadataVerificationKeyHash: Field,
|
223
|
+
nftVerificationKeyHash: Field,
|
224
|
+
expiry: UInt32,
|
225
|
+
}) {
|
226
|
+
}
|
227
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/mina/nft/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,SAAS,EACT,IAAI,EACJ,eAAe,EACf,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,GAEb,MAAM,MAAM,CAAC;AACd,OAAO,EACL,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,cAAc,EACd,QAAQ,EACR,iBAAiB,EACjB,cAAc,GAEf,CAAC;AAEF,MAAM,OAAQ,SAAQ,MAAM,CAAC;IAC3B,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;CAC9B,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t64, 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,120 @@
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
2
|
+
import { Bool, method, Permissions, Provable, PublicKey, SmartContract, State, state, VerificationKey, UInt64, Field, Poseidon, } from "o1js";
|
3
|
+
import { Whitelist, loadWhitelist } from "./whitelist";
|
4
|
+
import { MintParams, NFTState, Storage } from "./types";
|
5
|
+
export class NFTWhitelistedAdmin extends SmartContract {
|
6
|
+
constructor() {
|
7
|
+
super(...arguments);
|
8
|
+
this.admin = State();
|
9
|
+
this.whitelist = State();
|
10
|
+
this.storage = State();
|
11
|
+
}
|
12
|
+
async deploy(props) {
|
13
|
+
await super.deploy(props);
|
14
|
+
this.admin.set(props.admin);
|
15
|
+
this.whitelist.set(props.whitelist);
|
16
|
+
this.storage.set(props.storage);
|
17
|
+
this.account.permissions.set({
|
18
|
+
...Permissions.default(),
|
19
|
+
setVerificationKey: Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
20
|
+
setPermissions: Permissions.impossible(),
|
21
|
+
});
|
22
|
+
}
|
23
|
+
async isWhitelisted(address, amount) {
|
24
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
25
|
+
const storage = this.storage.getAndRequireEquals();
|
26
|
+
const map = await Provable.witnessAsync(Whitelist, async () => {
|
27
|
+
return await loadWhitelist(storage);
|
28
|
+
});
|
29
|
+
map.root.assertEquals(whitelist);
|
30
|
+
const key = Poseidon.hash(address.toFields());
|
31
|
+
map.assertIncluded(key, "Address not whitelisted");
|
32
|
+
const value = map.get(key);
|
33
|
+
value.assertLessThanOrEqual(Field(UInt64.MAXINT().value));
|
34
|
+
const maxAmount = UInt64.Unsafe.fromField(value);
|
35
|
+
return Bool(amount.lessThanOrEqual(maxAmount));
|
36
|
+
}
|
37
|
+
async updateVerificationKey(vk) {
|
38
|
+
const sender = this.sender.getAndRequireSignature();
|
39
|
+
this.admin.getAndRequireEquals().assertEquals(sender);
|
40
|
+
this.account.verificationKey.set(vk);
|
41
|
+
}
|
42
|
+
async canMint(params) {
|
43
|
+
return await this.isWhitelisted(params.owner, UInt64.from(0));
|
44
|
+
}
|
45
|
+
async canUpdate(input, output) {
|
46
|
+
return await this.isWhitelisted(output.owner, UInt64.from(0));
|
47
|
+
}
|
48
|
+
async canTransfer(address, from, to) {
|
49
|
+
return await this.isWhitelisted(to, UInt64.from(0));
|
50
|
+
}
|
51
|
+
async canSell(address, seller, price) {
|
52
|
+
return await this.isWhitelisted(address, price);
|
53
|
+
}
|
54
|
+
async canBuy(address, seller, buyer, price) {
|
55
|
+
return (await this.isWhitelisted(buyer, price)).and(await this.isWhitelisted(seller, price));
|
56
|
+
}
|
57
|
+
async updateMerkleMapRoot(root) {
|
58
|
+
const sender = this.sender.getAndRequireSignature();
|
59
|
+
this.admin.getAndRequireEquals().assertEquals(sender);
|
60
|
+
this.whitelist.set(root);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
__decorate([
|
64
|
+
state(PublicKey),
|
65
|
+
__metadata("design:type", Object)
|
66
|
+
], NFTWhitelistedAdmin.prototype, "admin", void 0);
|
67
|
+
__decorate([
|
68
|
+
state(Field),
|
69
|
+
__metadata("design:type", Object)
|
70
|
+
], NFTWhitelistedAdmin.prototype, "whitelist", void 0);
|
71
|
+
__decorate([
|
72
|
+
state(Storage),
|
73
|
+
__metadata("design:type", Object)
|
74
|
+
], NFTWhitelistedAdmin.prototype, "storage", void 0);
|
75
|
+
__decorate([
|
76
|
+
method,
|
77
|
+
__metadata("design:type", Function),
|
78
|
+
__metadata("design:paramtypes", [VerificationKey]),
|
79
|
+
__metadata("design:returntype", Promise)
|
80
|
+
], NFTWhitelistedAdmin.prototype, "updateVerificationKey", null);
|
81
|
+
__decorate([
|
82
|
+
method.returns(Bool),
|
83
|
+
__metadata("design:type", Function),
|
84
|
+
__metadata("design:paramtypes", [MintParams]),
|
85
|
+
__metadata("design:returntype", Promise)
|
86
|
+
], NFTWhitelistedAdmin.prototype, "canMint", null);
|
87
|
+
__decorate([
|
88
|
+
method.returns(Bool),
|
89
|
+
__metadata("design:type", Function),
|
90
|
+
__metadata("design:paramtypes", [NFTState, NFTState]),
|
91
|
+
__metadata("design:returntype", Promise)
|
92
|
+
], NFTWhitelistedAdmin.prototype, "canUpdate", null);
|
93
|
+
__decorate([
|
94
|
+
method.returns(Bool),
|
95
|
+
__metadata("design:type", Function),
|
96
|
+
__metadata("design:paramtypes", [PublicKey, PublicKey, PublicKey]),
|
97
|
+
__metadata("design:returntype", Promise)
|
98
|
+
], NFTWhitelistedAdmin.prototype, "canTransfer", null);
|
99
|
+
__decorate([
|
100
|
+
method.returns(Bool),
|
101
|
+
__metadata("design:type", Function),
|
102
|
+
__metadata("design:paramtypes", [PublicKey, PublicKey, UInt64]),
|
103
|
+
__metadata("design:returntype", Promise)
|
104
|
+
], NFTWhitelistedAdmin.prototype, "canSell", null);
|
105
|
+
__decorate([
|
106
|
+
method.returns(Bool),
|
107
|
+
__metadata("design:type", Function),
|
108
|
+
__metadata("design:paramtypes", [PublicKey,
|
109
|
+
PublicKey,
|
110
|
+
PublicKey,
|
111
|
+
UInt64]),
|
112
|
+
__metadata("design:returntype", Promise)
|
113
|
+
], NFTWhitelistedAdmin.prototype, "canBuy", null);
|
114
|
+
__decorate([
|
115
|
+
method,
|
116
|
+
__metadata("design:type", Function),
|
117
|
+
__metadata("design:paramtypes", [Field]),
|
118
|
+
__metadata("design:returntype", Promise)
|
119
|
+
], NFTWhitelistedAdmin.prototype, "updateMerkleMapRoot", null);
|
120
|
+
//# sourceMappingURL=whitelist-admin.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"whitelist-admin.js","sourceRoot":"","sources":["../../../../../../src/mina/nft/whitelist-admin.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,IAAI,EAEJ,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,EACT,aAAa,EACb,KAAK,EACL,KAAK,EACL,eAAe,EACf,MAAM,EAEN,KAAK,EACL,QAAQ,GACT,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAgB,OAAO,EAAE,MAAM,SAAS,CAAC;AAStE,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IAAtD;;QACoB,UAAK,GAAG,KAAK,EAAa,CAAC;QAC/B,cAAS,GAAG,KAAK,EAAS,CAAC;QACzB,YAAO,GAAG,KAAK,EAAW,CAAC;IA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ib/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,106 @@
|
|
1
|
+
import { Experimental, Field } from "o1js";
|
2
|
+
import { bigintToBase64, bigintFromBase64 } from "../../cloud";
|
3
|
+
const { IndexedMerkleMap } = Experimental;
|
4
|
+
const height = 10;
|
5
|
+
export class Whitelist extends IndexedMerkleMap(height) {
|
6
|
+
}
|
7
|
+
export async function loadWhitelist(storage) {
|
8
|
+
const url = "https://gateway.pinata.cloud/ipfs/" + storage.toURL();
|
9
|
+
const response = await fetch(url);
|
10
|
+
if (!response.ok) {
|
11
|
+
throw new Error("Failed to fetch whitelist");
|
12
|
+
}
|
13
|
+
const json = await response.text();
|
14
|
+
const map = deserializeWhitelist({
|
15
|
+
serializedIndexedMap: json,
|
16
|
+
type: Whitelist,
|
17
|
+
});
|
18
|
+
if (!map) {
|
19
|
+
throw new Error("Failed to deserialize whitelist");
|
20
|
+
}
|
21
|
+
return map;
|
22
|
+
}
|
23
|
+
export function serializeWhitelist(map) {
|
24
|
+
const serializedMap = JSON.stringify({
|
25
|
+
height: map.height,
|
26
|
+
root: map.root.toJSON(),
|
27
|
+
length: map.length.toJSON(),
|
28
|
+
nodes: JSON.stringify(map.data.get().nodes, (_, v) => typeof v === "bigint" ? "n" + bigintToBase64(v) : v),
|
29
|
+
sortedLeaves: JSON.stringify(map.data
|
30
|
+
.get()
|
31
|
+
.sortedLeaves.map((v) => [
|
32
|
+
bigintToBase64(v.key),
|
33
|
+
bigintToBase64(v.nextKey),
|
34
|
+
bigintToBase64(v.value),
|
35
|
+
bigintToBase64(BigInt(v.index)),
|
36
|
+
])),
|
37
|
+
}, null, 2);
|
38
|
+
return serializedMap;
|
39
|
+
}
|
40
|
+
export function deserializeWhitelist(params) {
|
41
|
+
try {
|
42
|
+
const { serializedIndexedMap, type } = params;
|
43
|
+
const json = parseIndexedMapSerialized(serializedIndexedMap);
|
44
|
+
return deserializeIndexedMapInternal({
|
45
|
+
json,
|
46
|
+
type: type ?? IndexedMerkleMap(json.height),
|
47
|
+
});
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
console.error("Error deserializing map:", error?.message ?? error);
|
51
|
+
return undefined;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
export function parseIndexedMapSerialized(serializedMap) {
|
55
|
+
const json = JSON.parse(serializedMap);
|
56
|
+
if (json.height === undefined ||
|
57
|
+
json.root === undefined ||
|
58
|
+
json.length === undefined ||
|
59
|
+
json.nodes === undefined ||
|
60
|
+
json.sortedLeaves === undefined)
|
61
|
+
throw new Error("wrong IndexedMerkleMap json format");
|
62
|
+
if (typeof json.height !== "number")
|
63
|
+
throw new Error("wrong IndexedMerkleMap height format");
|
64
|
+
if (typeof json.root !== "string")
|
65
|
+
throw new Error("wrong IndexedMerkleMap root format");
|
66
|
+
if (typeof json.length !== "string")
|
67
|
+
throw new Error("wrong IndexedMerkleMap length format");
|
68
|
+
if (typeof json.nodes !== "string")
|
69
|
+
throw new Error("wrong IndexedMerkleMap nodes format");
|
70
|
+
if (typeof json.sortedLeaves !== "string")
|
71
|
+
throw new Error("wrong IndexedMerkleMap sortedLeaves format");
|
72
|
+
return json;
|
73
|
+
}
|
74
|
+
function deserializeIndexedMapInternal(params) {
|
75
|
+
const { json, type } = params;
|
76
|
+
const map = new type();
|
77
|
+
if (json.height !== map.height) {
|
78
|
+
throw new Error("wrong IndexedMap height");
|
79
|
+
}
|
80
|
+
const nodes = JSON.parse(json.nodes, (_, v) => {
|
81
|
+
// Check if the value is a string that represents a BigInt
|
82
|
+
if (typeof v === "string" && v[0] === "n") {
|
83
|
+
// Remove the first 'n' and convert the string to a BigInt
|
84
|
+
return bigintFromBase64(v.slice(1));
|
85
|
+
}
|
86
|
+
return v;
|
87
|
+
});
|
88
|
+
const sortedLeaves = JSON.parse(json.sortedLeaves).map((row) => {
|
89
|
+
return {
|
90
|
+
key: bigintFromBase64(row[0]),
|
91
|
+
nextKey: bigintFromBase64(row[1]),
|
92
|
+
value: bigintFromBase64(row[2]),
|
93
|
+
index: Number(bigintFromBase64(row[3])),
|
94
|
+
};
|
95
|
+
});
|
96
|
+
map.root = Field.fromJSON(json.root);
|
97
|
+
map.length = Field.fromJSON(json.length);
|
98
|
+
map.data.updateAsProver(() => {
|
99
|
+
return {
|
100
|
+
nodes: nodes.map((row) => [...row]),
|
101
|
+
sortedLeaves: [...sortedLeaves],
|
102
|
+
};
|
103
|
+
});
|
104
|
+
return map;
|
105
|
+
}
|
106
|
+
//# sourceMappingURL=whitelist.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"whitelist.js","sourceRoot":"","sources":["../../../../../../src/mina/nft/whitelist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/D,MAAM,EAAE,gBAAgB,EAAE,GAAG,YAAY,CAAC;AAC1C,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,OAAO,SAAU,SAAQ,gBAAgB,CAAC,M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