@peeramid-labs/sdk 3.7.4 → 3.8.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.
- package/cli/cli/commands/blockchain/index.js +9 -0
- package/cli/cli/commands/blockchain/index.js.map +1 -0
- package/cli/cli/commands/blockchain/mine.js +45 -0
- package/cli/cli/commands/blockchain/mine.js.map +1 -0
- package/cli/cli/commands/distributions/add.js +55 -31
- package/cli/cli/commands/distributions/add.js.map +1 -1
- package/cli/cli/commands/fellowship/create.js +96 -60
- package/cli/cli/commands/fellowship/create.js.map +1 -1
- package/cli/cli/commands/fellowship/game/cancel.js +45 -0
- package/cli/cli/commands/fellowship/game/cancel.js.map +1 -0
- package/cli/cli/commands/fellowship/game/create.js +91 -0
- package/cli/cli/commands/fellowship/game/create.js.map +1 -0
- package/cli/cli/commands/fellowship/{endTurn.js → game/end-turn.js} +8 -7
- package/cli/cli/commands/fellowship/game/end-turn.js.map +1 -0
- package/cli/cli/commands/fellowship/game/index.js +31 -0
- package/cli/cli/commands/fellowship/game/index.js.map +1 -0
- package/cli/cli/commands/fellowship/game/join.js +131 -0
- package/cli/cli/commands/fellowship/game/join.js.map +1 -0
- package/cli/cli/commands/fellowship/{games.js → game/list.js} +5 -5
- package/cli/cli/commands/fellowship/game/list.js.map +1 -0
- package/cli/cli/commands/fellowship/game/propose.js +178 -0
- package/cli/cli/commands/fellowship/game/propose.js.map +1 -0
- package/cli/cli/commands/fellowship/game/start.js +117 -0
- package/cli/cli/commands/fellowship/game/start.js.map +1 -0
- package/cli/cli/commands/fellowship/game/vote.js +114 -0
- package/cli/cli/commands/fellowship/game/vote.js.map +1 -0
- package/cli/cli/commands/fellowship/index.js +3 -5
- package/cli/cli/commands/fellowship/index.js.map +1 -1
- package/cli/cli/commands/getPk.js +48 -0
- package/cli/cli/commands/getPk.js.map +1 -0
- package/cli/cli/commands/playbook.js +92 -0
- package/cli/cli/commands/playbook.js.map +1 -0
- package/cli/cli/getPk.js +62 -0
- package/cli/cli/getPk.js.map +1 -0
- package/cli/cli/helpers.js +64 -0
- package/cli/cli/helpers.js.map +1 -0
- package/cli/cli/index.js +6 -0
- package/cli/cli/index.js.map +1 -1
- package/cli/cli/utils.js +64 -0
- package/cli/cli/utils.js.map +1 -0
- package/cli/rankify/GameMaster.js +199 -209
- package/cli/rankify/GameMaster.js.map +1 -1
- package/cli/rankify/InstanceBase.js +60 -36
- package/cli/rankify/InstanceBase.js.map +1 -1
- package/cli/rankify/Player.js +355 -0
- package/cli/rankify/Player.js.map +1 -0
- package/cli/utils/blockchain.js +62 -0
- package/cli/utils/blockchain.js.map +1 -0
- package/docs/classes/GameMaster.md +23 -63
- package/docs/classes/InstanceBase.md +21 -27
- package/docs/classes/InstancePlayer.md +25 -31
- package/docs/docs/classes/GameMaster.md +23 -63
- package/docs/docs/classes/InstanceBase.md +21 -27
- package/docs/docs/classes/InstancePlayer.md +25 -31
- package/docs/docs/index.md +1 -1
- package/docs/index.md +1 -1
- package/lib.commonjs/rankify/GameMaster.d.ts +26 -33
- package/lib.commonjs/rankify/GameMaster.d.ts.map +1 -1
- package/lib.commonjs/rankify/GameMaster.js +199 -209
- package/lib.commonjs/rankify/GameMaster.js.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.d.ts +64 -50
- package/lib.commonjs/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.js +60 -36
- package/lib.commonjs/rankify/InstanceBase.js.map +1 -1
- package/lib.commonjs/utils/blockchain.d.ts +32 -0
- package/lib.commonjs/utils/blockchain.d.ts.map +1 -0
- package/lib.commonjs/utils/blockchain.js +62 -0
- package/lib.commonjs/utils/blockchain.js.map +1 -0
- package/lib.esm/rankify/GameMaster.d.ts +26 -33
- package/lib.esm/rankify/GameMaster.d.ts.map +1 -1
- package/lib.esm/rankify/GameMaster.js +199 -209
- package/lib.esm/rankify/GameMaster.js.map +1 -1
- package/lib.esm/rankify/InstanceBase.d.ts +64 -50
- package/lib.esm/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.esm/rankify/InstanceBase.js +60 -36
- package/lib.esm/rankify/InstanceBase.js.map +1 -1
- package/lib.esm/utils/blockchain.d.ts +32 -0
- package/lib.esm/utils/blockchain.d.ts.map +1 -0
- package/lib.esm/utils/blockchain.js +58 -0
- package/lib.esm/utils/blockchain.js.map +1 -0
- package/package.json +1 -1
- package/cli/cli/commands/fellowship/endTurn.js.map +0 -1
- package/cli/cli/commands/fellowship/games.js.map +0 -1
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const artifacts_1 = require("../utils/artifacts");
|
|
8
|
+
const RankifyDiamondInstance_1 = __importDefault(require("../abis/RankifyDiamondInstance"));
|
|
9
|
+
const InstanceBase_1 = __importDefault(require("./InstanceBase"));
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
class RankifyPlayer extends InstanceBase_1.default {
|
|
12
|
+
constructor({ publicClient, walletClient, chainId, instanceAddress, account, }) {
|
|
13
|
+
super({
|
|
14
|
+
publicClient,
|
|
15
|
+
chainId,
|
|
16
|
+
instanceAddress,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Approves the necessary tokens if needed
|
|
20
|
+
* @param value - The amount of tokens to approve
|
|
21
|
+
* @returns A promise that resolves when the tokens are approved
|
|
22
|
+
* @throws If the account is not found or the tokens cannot be approved
|
|
23
|
+
*/
|
|
24
|
+
this.approveTokensIfNeeded = async (value) => {
|
|
25
|
+
const tokenContract = (0, artifacts_1.getContract)(this.chainId, "Rankify", this.walletClient);
|
|
26
|
+
if (!this.walletClient.account?.address)
|
|
27
|
+
throw new Error("Account not found");
|
|
28
|
+
if (value > 0n) {
|
|
29
|
+
try {
|
|
30
|
+
const { request } = await this.publicClient.simulateContract({
|
|
31
|
+
address: tokenContract.address,
|
|
32
|
+
abi: tokenContract.abi,
|
|
33
|
+
functionName: "approve",
|
|
34
|
+
args: [this.instanceAddress, value],
|
|
35
|
+
account: this.walletClient.account,
|
|
36
|
+
});
|
|
37
|
+
const hash = await this.walletClient.writeContract(request);
|
|
38
|
+
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new game
|
|
47
|
+
* @param creationArgs - The arguments for creating a new game
|
|
48
|
+
* @param openNow - Whether to open the game registration immediately
|
|
49
|
+
* @returns A promise that resolves to the game ID and receipt
|
|
50
|
+
* @throws If the account is not found or the game cannot be created
|
|
51
|
+
*/
|
|
52
|
+
this.createGame = async ({ creationArgs, openNow, }) => {
|
|
53
|
+
// if (!creationArgs) throw new Error("args is required");
|
|
54
|
+
try {
|
|
55
|
+
const estimationArgs = [
|
|
56
|
+
creationArgs.minGameTime,
|
|
57
|
+
];
|
|
58
|
+
const price = await this.publicClient.readContract({
|
|
59
|
+
address: this.instanceAddress,
|
|
60
|
+
abi: RankifyDiamondInstance_1.default,
|
|
61
|
+
functionName: "estimateGamePrice",
|
|
62
|
+
args: estimationArgs,
|
|
63
|
+
});
|
|
64
|
+
await this.approveTokensIfNeeded(price);
|
|
65
|
+
if (!this.walletClient.account?.address)
|
|
66
|
+
throw new Error("Account not found");
|
|
67
|
+
const { request } = await this.publicClient.simulateContract({
|
|
68
|
+
address: this.instanceAddress,
|
|
69
|
+
abi: RankifyDiamondInstance_1.default,
|
|
70
|
+
functionName: "createGame",
|
|
71
|
+
args: [creationArgs],
|
|
72
|
+
account: this.walletClient.account.address,
|
|
73
|
+
});
|
|
74
|
+
const hash = await this.walletClient.writeContract(request);
|
|
75
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
76
|
+
const events = await this.publicClient.getContractEvents({
|
|
77
|
+
address: this.instanceAddress,
|
|
78
|
+
abi: RankifyDiamondInstance_1.default,
|
|
79
|
+
eventName: "gameCreated",
|
|
80
|
+
args: {},
|
|
81
|
+
fromBlock: receipt.blockNumber,
|
|
82
|
+
toBlock: receipt.blockNumber,
|
|
83
|
+
});
|
|
84
|
+
if (events.length > 1) {
|
|
85
|
+
throw new Error("Failed to create game: Multiple GameCreated events found");
|
|
86
|
+
}
|
|
87
|
+
if (events.length === 0) {
|
|
88
|
+
throw new Error("Failed to create game: GameCreated event not found");
|
|
89
|
+
}
|
|
90
|
+
if (!events[0].args)
|
|
91
|
+
throw new Error("Failed to create game: Event args not found");
|
|
92
|
+
if (!("gameId" in events[0].args))
|
|
93
|
+
throw new Error("Failed to create game: GameId not found");
|
|
94
|
+
const { gameId } = events[0].args;
|
|
95
|
+
let openingReceipt;
|
|
96
|
+
if (openNow) {
|
|
97
|
+
if (!gameId)
|
|
98
|
+
throw new Error("Failed to create game: GameId not found");
|
|
99
|
+
openingReceipt = await this.openRegistration(gameId);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
gameId,
|
|
103
|
+
receipt,
|
|
104
|
+
openingReceipt,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Joins a game
|
|
113
|
+
* @param params - The parameters for joining a game
|
|
114
|
+
* @returns A promise that resolves to the transaction receipt
|
|
115
|
+
* @throws If the account is not found or the game cannot be joined
|
|
116
|
+
*/
|
|
117
|
+
this.joinGame = async ({ gameId, signature, gmCommitment, deadline, pubkey, }) => {
|
|
118
|
+
try {
|
|
119
|
+
const reqs = (await this.publicClient.readContract({
|
|
120
|
+
address: this.instanceAddress,
|
|
121
|
+
abi: RankifyDiamondInstance_1.default,
|
|
122
|
+
functionName: "getJoinRequirements",
|
|
123
|
+
args: [gameId],
|
|
124
|
+
}));
|
|
125
|
+
const values = reqs.ethValues;
|
|
126
|
+
const value = values.bet + values.burn + values.pay;
|
|
127
|
+
if (!this.walletClient.account?.address)
|
|
128
|
+
throw new Error("Account not found");
|
|
129
|
+
const { request } = await this.publicClient.simulateContract({
|
|
130
|
+
address: this.instanceAddress,
|
|
131
|
+
abi: RankifyDiamondInstance_1.default,
|
|
132
|
+
functionName: "joinGame",
|
|
133
|
+
args: [gameId, signature, gmCommitment, BigInt(deadline), pubkey],
|
|
134
|
+
value,
|
|
135
|
+
account: this.walletClient.account,
|
|
136
|
+
});
|
|
137
|
+
const hash = await this.walletClient.writeContract(request);
|
|
138
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
this.estimateGamePrice = async (minimumGameTime) => {
|
|
145
|
+
try {
|
|
146
|
+
const estimationArgs = [
|
|
147
|
+
minimumGameTime,
|
|
148
|
+
];
|
|
149
|
+
const price = await this.publicClient.readContract({
|
|
150
|
+
address: this.instanceAddress,
|
|
151
|
+
abi: RankifyDiamondInstance_1.default,
|
|
152
|
+
functionName: "estimateGamePrice",
|
|
153
|
+
args: estimationArgs,
|
|
154
|
+
});
|
|
155
|
+
return price;
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Starts a game
|
|
163
|
+
* @param gameId - The ID of the game to start
|
|
164
|
+
* @param permutationCommitment - The permutation commitment for the game
|
|
165
|
+
* @returns A promise that resolves to the transaction receipt
|
|
166
|
+
* @throws If the account is not found or the game cannot be started
|
|
167
|
+
*/
|
|
168
|
+
this.startGame = async (gameId, permutationCommitment) => {
|
|
169
|
+
try {
|
|
170
|
+
if (!this.walletClient.account?.address)
|
|
171
|
+
throw new Error("Account not found");
|
|
172
|
+
const { request } = await this.publicClient.simulateContract({
|
|
173
|
+
address: this.instanceAddress,
|
|
174
|
+
abi: RankifyDiamondInstance_1.default,
|
|
175
|
+
functionName: "startGame",
|
|
176
|
+
args: [gameId, permutationCommitment],
|
|
177
|
+
account: this.walletClient.account,
|
|
178
|
+
});
|
|
179
|
+
const hash = await this.walletClient.writeContract(request);
|
|
180
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Cancels a game
|
|
188
|
+
* @param gameId - The ID of the game to cancel
|
|
189
|
+
* @returns A promise that resolves to the transaction receipt
|
|
190
|
+
* @throws If the account is not found or the game cannot be canceled
|
|
191
|
+
*/
|
|
192
|
+
this.cancelGame = async (gameId) => {
|
|
193
|
+
try {
|
|
194
|
+
if (!this.walletClient.account?.address)
|
|
195
|
+
throw new Error("Account not found");
|
|
196
|
+
const { request } = await this.publicClient.simulateContract({
|
|
197
|
+
address: this.instanceAddress,
|
|
198
|
+
abi: RankifyDiamondInstance_1.default,
|
|
199
|
+
functionName: "cancelGame",
|
|
200
|
+
args: [gameId],
|
|
201
|
+
account: this.walletClient.account,
|
|
202
|
+
});
|
|
203
|
+
const hash = await this.walletClient.writeContract(request);
|
|
204
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Leaves a game
|
|
212
|
+
* @param gameId - The ID of the game to leave
|
|
213
|
+
* @returns A promise that resolves to the transaction receipt
|
|
214
|
+
* @throws If the account is not found or the game cannot be left
|
|
215
|
+
*/
|
|
216
|
+
this.leaveGame = async (gameId) => {
|
|
217
|
+
try {
|
|
218
|
+
if (!this.walletClient.account?.address)
|
|
219
|
+
throw new Error("Account not found");
|
|
220
|
+
const { request } = await this.publicClient.simulateContract({
|
|
221
|
+
address: this.instanceAddress,
|
|
222
|
+
abi: RankifyDiamondInstance_1.default,
|
|
223
|
+
functionName: "leaveGame",
|
|
224
|
+
args: [gameId],
|
|
225
|
+
account: this.walletClient.account,
|
|
226
|
+
});
|
|
227
|
+
const hash = await this.walletClient.writeContract(request);
|
|
228
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Opens the registration for a game
|
|
236
|
+
* @param gameId - The ID of the game to open registration for
|
|
237
|
+
* @returns A promise that resolves to the transaction receipt
|
|
238
|
+
* @throws If the account is not found or the registration cannot be opened
|
|
239
|
+
*/
|
|
240
|
+
this.openRegistration = async (gameId) => {
|
|
241
|
+
try {
|
|
242
|
+
if (!this.walletClient.account?.address)
|
|
243
|
+
throw new Error("Account not found");
|
|
244
|
+
const { request } = await this.publicClient.simulateContract({
|
|
245
|
+
address: this.instanceAddress,
|
|
246
|
+
abi: RankifyDiamondInstance_1.default,
|
|
247
|
+
functionName: "openRegistration",
|
|
248
|
+
args: [gameId],
|
|
249
|
+
account: this.walletClient.account,
|
|
250
|
+
});
|
|
251
|
+
const hash = await this.walletClient.writeContract(request);
|
|
252
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
throw await (0, utils_1.handleRPCError)(e);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Sets the join requirements for a game
|
|
260
|
+
* @param params - The parameters for setting the join requirements
|
|
261
|
+
* @returns A promise that resolves to the transaction receipt
|
|
262
|
+
* @throws If the account is not found or the join requirements cannot be set
|
|
263
|
+
*/
|
|
264
|
+
this.setJoinRequirements = async (params) => {
|
|
265
|
+
if (!this.walletClient.account?.address)
|
|
266
|
+
throw new Error("Account not found");
|
|
267
|
+
if (!params)
|
|
268
|
+
throw new Error("params is required");
|
|
269
|
+
try {
|
|
270
|
+
const { request } = await this.publicClient.simulateContract({
|
|
271
|
+
address: this.instanceAddress,
|
|
272
|
+
abi: RankifyDiamondInstance_1.default,
|
|
273
|
+
functionName: "setJoinRequirements",
|
|
274
|
+
args: params,
|
|
275
|
+
account: this.walletClient.account,
|
|
276
|
+
});
|
|
277
|
+
const hash = await this.walletClient.writeContract(request);
|
|
278
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
await (0, utils_1.handleRPCError)(e);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Signs a proposal commitment
|
|
286
|
+
* @param params - The parameters for signing a proposal commitment
|
|
287
|
+
* @returns A promise that resolves to the signed proposal commitment
|
|
288
|
+
* @throws If the account is not found or the proposal commitment cannot be signed
|
|
289
|
+
*/
|
|
290
|
+
this.signProposalCommitment = async (params) => {
|
|
291
|
+
const proposalTypes = {
|
|
292
|
+
AuthorizeProposalSubmission: [
|
|
293
|
+
{ type: "uint256", name: "gameId" },
|
|
294
|
+
{ type: "string", name: "encryptedProposal" },
|
|
295
|
+
{ type: "uint256", name: "commitment" },
|
|
296
|
+
],
|
|
297
|
+
};
|
|
298
|
+
const eip712 = await this.getEIP712Domain();
|
|
299
|
+
return this.walletClient.signTypedData({
|
|
300
|
+
domain: {
|
|
301
|
+
name: eip712.name,
|
|
302
|
+
version: eip712.version,
|
|
303
|
+
chainId: eip712.chainId,
|
|
304
|
+
verifyingContract: this.instanceAddress,
|
|
305
|
+
},
|
|
306
|
+
types: proposalTypes,
|
|
307
|
+
primaryType: "AuthorizeProposalSubmission",
|
|
308
|
+
message: {
|
|
309
|
+
gameId: params.gameId,
|
|
310
|
+
encryptedProposal: params.encryptedProposal,
|
|
311
|
+
commitment: params.commitment,
|
|
312
|
+
},
|
|
313
|
+
account: this.account,
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Signs an authorize vote submission
|
|
318
|
+
* @param params - The parameters for signing an authorize vote submission
|
|
319
|
+
* @returns A promise that resolves to the signed authorize vote submission
|
|
320
|
+
* @throws If the account is not found or the authorize vote submission cannot be signed
|
|
321
|
+
*/
|
|
322
|
+
this.authorizeVoteSubmission = async (params) => {
|
|
323
|
+
const voteTypes = {
|
|
324
|
+
AuthorizeVoteSubmission: [
|
|
325
|
+
{ name: "gameId", type: "uint256" },
|
|
326
|
+
{ name: "sealedBallotId", type: "string" },
|
|
327
|
+
{ name: "ballotHash", type: "bytes32" },
|
|
328
|
+
],
|
|
329
|
+
};
|
|
330
|
+
const { gameId, vote, verifierAddress, playerSalt, ballotId } = params;
|
|
331
|
+
const eip712 = await this.getEIP712Domain();
|
|
332
|
+
const ballotHash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["uint256[]", "bytes32"], [vote, playerSalt]));
|
|
333
|
+
return this.walletClient.signTypedData({
|
|
334
|
+
domain: {
|
|
335
|
+
name: eip712.name,
|
|
336
|
+
version: eip712.version,
|
|
337
|
+
chainId: this.chainId,
|
|
338
|
+
verifyingContract: verifierAddress,
|
|
339
|
+
},
|
|
340
|
+
types: voteTypes,
|
|
341
|
+
primaryType: "AuthorizeVoteSubmission",
|
|
342
|
+
message: {
|
|
343
|
+
gameId,
|
|
344
|
+
sealedBallotId: ballotId,
|
|
345
|
+
ballotHash,
|
|
346
|
+
},
|
|
347
|
+
account: this.account,
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
this.walletClient = walletClient;
|
|
351
|
+
this.account = account;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
exports.default = RankifyPlayer;
|
|
355
|
+
//# sourceMappingURL=Player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Player.js","sourceRoot":"","sources":["../../../src/rankify/Player.ts"],"names":[],"mappings":";;;;;AAAA,+BAUc;AACd,kDAAiD;AACjD,4FAAyD;AACzD,kEAA0C;AAC1C,oCAA0C;AAyB1C,MAAqB,aAAc,SAAQ,sBAAY;IAIrD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,eAAe,EACf,OAAO,GAOR;QACC,KAAK,CAAC;YACJ,YAAY;YACZ,OAAO;YACP,eAAe;SAChB,CAAC,CAAC;QAKL;;;;;WAKG;QACH,0BAAqB,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE;YAC9C,MAAM,aAAa,GAAG,IAAA,uBAAW,EAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9E,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC9E,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;gBACf,IAAI,CAAC;oBACH,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;wBAC3D,OAAO,EAAE,aAAa,CAAC,OAAO;wBAC9B,GAAG,EAAE,aAAa,CAAC,GAAG;wBACtB,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC;wBACnC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;qBACnC,CAAC,CAAC;oBAEH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBAC5D,MAAM,IAAI,CAAC,YAAY,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,CAA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ACnC;gBACD,KAAK,EAAE,SAAS;gBAChB,WAAW,EAAE,yBAAyB;gBACtC,OAAO,EAAE;oBACP,MAAM;oBACN,cAAc,EAAE,QAAQ;oBACxB,UAAU;iBACX;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC,CAAC;QA7WA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CA4WF;AApYD,gCAoYC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockchainUtils = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility functions for blockchain operations
|
|
6
|
+
*/
|
|
7
|
+
class BlockchainUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the current chain is a local development chain
|
|
10
|
+
* @param chainId The chain ID to check
|
|
11
|
+
* @returns True if the chain is a local development chain
|
|
12
|
+
*/
|
|
13
|
+
static isLocalChain(chainId) {
|
|
14
|
+
// Hardhat = 31337, Ganache = 1337, Anvil = 97113
|
|
15
|
+
return chainId === 31337 || chainId === 1337 || chainId === 97113;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Increases the next block timestamp and mines a new block
|
|
19
|
+
* @param publicClient The viem public client
|
|
20
|
+
* @param timeIncrease Number of seconds to increase the timestamp by
|
|
21
|
+
* @param spinner Optional ora spinner for displaying progress
|
|
22
|
+
* @returns Object containing the old and new block information
|
|
23
|
+
*/
|
|
24
|
+
static async increaseTimeAndMine(publicClient, timeIncrease, spinner) {
|
|
25
|
+
// Get current block
|
|
26
|
+
const currentBlock = await publicClient.getBlock({ blockTag: "latest" });
|
|
27
|
+
if (spinner) {
|
|
28
|
+
spinner.info(`Current block: ${currentBlock.number}, timestamp: ${currentBlock.timestamp}`);
|
|
29
|
+
}
|
|
30
|
+
// Calculate new timestamp
|
|
31
|
+
const newTimestamp = Number(currentBlock.timestamp) + timeIncrease;
|
|
32
|
+
if (spinner) {
|
|
33
|
+
spinner.start(`Increasing block timestamp by ${timeIncrease} seconds and mining a new block...`);
|
|
34
|
+
}
|
|
35
|
+
// Use JSON-RPC methods directly to manipulate local blockchain
|
|
36
|
+
// First, set the next block's timestamp
|
|
37
|
+
await publicClient.transport.request({
|
|
38
|
+
method: "evm_setNextBlockTimestamp",
|
|
39
|
+
params: [newTimestamp],
|
|
40
|
+
});
|
|
41
|
+
// Then mine a block
|
|
42
|
+
await publicClient.transport.request({
|
|
43
|
+
method: "evm_mine",
|
|
44
|
+
params: [],
|
|
45
|
+
});
|
|
46
|
+
// Get the new block to confirm changes
|
|
47
|
+
const newBlock = await publicClient.getBlock({ blockTag: "latest" });
|
|
48
|
+
return {
|
|
49
|
+
oldBlock: {
|
|
50
|
+
number: currentBlock.number,
|
|
51
|
+
timestamp: currentBlock.timestamp
|
|
52
|
+
},
|
|
53
|
+
newBlock: {
|
|
54
|
+
number: newBlock.number,
|
|
55
|
+
timestamp: newBlock.timestamp
|
|
56
|
+
},
|
|
57
|
+
actualIncrease: Number(newBlock.timestamp) - Number(currentBlock.timestamp)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.BlockchainUtils = BlockchainUtils;
|
|
62
|
+
//# sourceMappingURL=blockchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../../src/utils/blockchain.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAa,eAAe;IAC1B;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,OAAe;QACjC,iDAAiD;QACjD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAC9B,YAA0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,0CAqEC"}
|
|
@@ -25,7 +25,6 @@ Extends InstanceBase to provide game master specific functionality
|
|
|
25
25
|
- [reversePermutation](GameMaster.md#reversepermutation)
|
|
26
26
|
- [getTurnSalt](GameMaster.md#getturnsalt)
|
|
27
27
|
- [getTurnPlayersSalt](GameMaster.md#getturnplayerssalt)
|
|
28
|
-
- [getProposalsVotedUpon](GameMaster.md#getproposalsvotedupon)
|
|
29
28
|
- [findPlayerOngoingProposalIndex](GameMaster.md#findplayerongoingproposalindex)
|
|
30
29
|
- [validateJoinGame](GameMaster.md#validatejoingame)
|
|
31
30
|
- [signJoiningGame](GameMaster.md#signjoininggame)
|
|
@@ -35,7 +34,6 @@ Extends InstanceBase to provide game master specific functionality
|
|
|
35
34
|
- [attestProposal](GameMaster.md#attestproposal)
|
|
36
35
|
- [submitProposal](GameMaster.md#submitproposal)
|
|
37
36
|
- [decryptTurnVotes](GameMaster.md#decryptturnvotes)
|
|
38
|
-
- [decryptVotes](GameMaster.md#decryptvotes)
|
|
39
37
|
- [canEndTurn](GameMaster.md#canendturn)
|
|
40
38
|
- [currentTurn](GameMaster.md#currentturn)
|
|
41
39
|
- [getPlayers](GameMaster.md#getplayers)
|
|
@@ -116,23 +114,25 @@ ___
|
|
|
116
114
|
|
|
117
115
|
### decryptProposals
|
|
118
116
|
|
|
119
|
-
▸ **decryptProposals**(`«destructured»`): `Promise`\<\{ `proposer`: \`0x$\{string}\`
|
|
117
|
+
▸ **decryptProposals**(`«destructured»`): `Promise`\<\{ `proposer`: \`0x$\{string}\` ; `proposal`: `string` }[]\>
|
|
120
118
|
|
|
121
119
|
Decrypts proposals for a specific game turn
|
|
122
120
|
|
|
123
121
|
#### Parameters
|
|
124
122
|
|
|
125
|
-
| Name | Type |
|
|
126
|
-
| :------ | :------ |
|
|
127
|
-
| `«destructured»` | `Object` |
|
|
128
|
-
| › `instanceAddress` | \`0x$\{string}\` |
|
|
129
|
-
| › `gameId` | `bigint` |
|
|
130
|
-
| › `turn` | `bigint` |
|
|
131
|
-
| › `
|
|
123
|
+
| Name | Type | Default value |
|
|
124
|
+
| :------ | :------ | :------ |
|
|
125
|
+
| `«destructured»` | `Object` | `undefined` |
|
|
126
|
+
| › `instanceAddress` | \`0x$\{string}\` | `undefined` |
|
|
127
|
+
| › `gameId` | `bigint` | `undefined` |
|
|
128
|
+
| › `turn` | `bigint` | `undefined` |
|
|
129
|
+
| › `players` | \`0x$\{string}\`[] | `undefined` |
|
|
130
|
+
| › `padToMaxSize?` | `boolean` | `false` |
|
|
131
|
+
| › `permute?` | `boolean` | `false` |
|
|
132
132
|
|
|
133
133
|
#### Returns
|
|
134
134
|
|
|
135
|
-
`Promise`\<\{ `proposer`: \`0x$\{string}\`
|
|
135
|
+
`Promise`\<\{ `proposer`: \`0x$\{string}\` ; `proposal`: `string` }[]\>
|
|
136
136
|
|
|
137
137
|
Array of decrypted proposals with proposer addresses
|
|
138
138
|
|
|
@@ -164,7 +164,7 @@ ___
|
|
|
164
164
|
|
|
165
165
|
### generateDeterministicPermutation
|
|
166
166
|
|
|
167
|
-
▸ **generateDeterministicPermutation**(`«destructured»`): `Promise`\<\{ `permutation`: `number`[] ; `
|
|
167
|
+
▸ **generateDeterministicPermutation**(`«destructured»`): `Promise`\<\{ `permutation`: `number`[] ; `turnSalt`: `bigint` ; `commitment`: `bigint` }\>
|
|
168
168
|
|
|
169
169
|
Generates a deterministic permutation for a specific game turn
|
|
170
170
|
|
|
@@ -180,7 +180,7 @@ Generates a deterministic permutation for a specific game turn
|
|
|
180
180
|
|
|
181
181
|
#### Returns
|
|
182
182
|
|
|
183
|
-
`Promise`\<\{ `permutation`: `number`[] ; `
|
|
183
|
+
`Promise`\<\{ `permutation`: `number`[] ; `turnSalt`: `bigint` ; `commitment`: `bigint` }\>
|
|
184
184
|
|
|
185
185
|
The generated permutation, secret, and commitment
|
|
186
186
|
|
|
@@ -294,25 +294,6 @@ Generated salt as Hex
|
|
|
294
294
|
|
|
295
295
|
___
|
|
296
296
|
|
|
297
|
-
### getProposalsVotedUpon
|
|
298
|
-
|
|
299
|
-
▸ **getProposalsVotedUpon**(`«destructured»`): `Promise`\<\{ `proposer`: \`0x$\{string}\` ; `proposal`: `string` }[]\>
|
|
300
|
-
|
|
301
|
-
#### Parameters
|
|
302
|
-
|
|
303
|
-
| Name | Type |
|
|
304
|
-
| :------ | :------ |
|
|
305
|
-
| `«destructured»` | `Object` |
|
|
306
|
-
| › `instanceAddress` | \`0x$\{string}\` |
|
|
307
|
-
| › `gameId` | `bigint` |
|
|
308
|
-
| › `turn` | `bigint` |
|
|
309
|
-
|
|
310
|
-
#### Returns
|
|
311
|
-
|
|
312
|
-
`Promise`\<\{ `proposer`: \`0x$\{string}\` ; `proposal`: `string` }[]\>
|
|
313
|
-
|
|
314
|
-
___
|
|
315
|
-
|
|
316
297
|
### findPlayerOngoingProposalIndex
|
|
317
298
|
|
|
318
299
|
▸ **findPlayerOngoingProposalIndex**(`«destructured»`): `Promise`\<`number`\>
|
|
@@ -500,44 +481,23 @@ ___
|
|
|
500
481
|
|
|
501
482
|
### decryptTurnVotes
|
|
502
483
|
|
|
503
|
-
▸ **decryptTurnVotes**(`«destructured»`): `Promise
|
|
484
|
+
▸ **decryptTurnVotes**(`«destructured»`): `Promise`\<`bigint`[][]\>
|
|
504
485
|
|
|
505
486
|
Decrypts votes for a specific game turn
|
|
506
487
|
|
|
507
488
|
#### Parameters
|
|
508
489
|
|
|
509
|
-
| Name | Type |
|
|
510
|
-
| :------ | :------ |
|
|
511
|
-
| `«destructured»` | `Object` |
|
|
512
|
-
| › `instanceAddress` | \`0x$\{string}\` |
|
|
513
|
-
| › `gameId` | `bigint` |
|
|
514
|
-
| › `turn` | `bigint` |
|
|
515
|
-
|
|
516
|
-
#### Returns
|
|
517
|
-
|
|
518
|
-
`Promise`\<\{ `player`: \`0x$\{string}\` = event.args.player; `votes`: `bigint`[] = decryptedVotes }[]\>
|
|
519
|
-
|
|
520
|
-
Array of decrypted votes with player addresses
|
|
521
|
-
|
|
522
|
-
___
|
|
523
|
-
|
|
524
|
-
### decryptVotes
|
|
525
|
-
|
|
526
|
-
▸ **decryptVotes**(`gameId`): `Promise`\<``-1`` \| \{ `player`: \`0x$\{string}\` = event.args.player; `votes`: `bigint`[] = decryptedVotes }[]\>
|
|
527
|
-
|
|
528
|
-
Decrypts all votes for the current game turn
|
|
529
|
-
|
|
530
|
-
#### Parameters
|
|
531
|
-
|
|
532
|
-
| Name | Type | Description |
|
|
490
|
+
| Name | Type | Default value |
|
|
533
491
|
| :------ | :------ | :------ |
|
|
534
|
-
|
|
|
535
|
-
| `
|
|
536
|
-
| `gameId
|
|
492
|
+
| `«destructured»` | `Object` | `undefined` |
|
|
493
|
+
| › `instanceAddress` | \`0x$\{string}\` | `undefined` |
|
|
494
|
+
| › `gameId` | `bigint` | `undefined` |
|
|
495
|
+
| › `turn` | `bigint` | `undefined` |
|
|
496
|
+
| › `players` | \`0x$\{string}\`[] | `[]` |
|
|
537
497
|
|
|
538
498
|
#### Returns
|
|
539
499
|
|
|
540
|
-
`Promise
|
|
500
|
+
`Promise`\<`bigint`[][]\>
|
|
541
501
|
|
|
542
502
|
Array of decrypted votes with player addresses
|
|
543
503
|
|
|
@@ -703,7 +663,7 @@ ___
|
|
|
703
663
|
|
|
704
664
|
### generateEndTurnIntegrity
|
|
705
665
|
|
|
706
|
-
▸ **generateEndTurnIntegrity**(`params`): `Promise`\<\{ `commitment`: `bigint` = inputs.permutationCommitment; `
|
|
666
|
+
▸ **generateEndTurnIntegrity**(`params`): `Promise`\<\{ `commitment`: `bigint` = inputs.permutationCommitment; `prevTurnSalt`: `bigint` ; `prevTurnPermutation`: `number`[] ; `permutedProposals`: `string`[] ; `a`: readonly [`bigint`, `bigint`] ; `b`: readonly [readonly [`bigint`, `bigint`], readonly [`bigint`, `bigint`]] ; `c`: readonly [`bigint`, `bigint`] }\>
|
|
707
667
|
|
|
708
668
|
Generates integrity data for the end of a game turn
|
|
709
669
|
|
|
@@ -720,7 +680,7 @@ Generates integrity data for the end of a game turn
|
|
|
720
680
|
|
|
721
681
|
#### Returns
|
|
722
682
|
|
|
723
|
-
`Promise`\<\{ `commitment`: `bigint` = inputs.permutationCommitment; `
|
|
683
|
+
`Promise`\<\{ `commitment`: `bigint` = inputs.permutationCommitment; `prevTurnSalt`: `bigint` ; `prevTurnPermutation`: `number`[] ; `permutedProposals`: `string`[] ; `a`: readonly [`bigint`, `bigint`] ; `b`: readonly [readonly [`bigint`, `bigint`], readonly [`bigint`, `bigint`]] ; `c`: readonly [`bigint`, `bigint`] }\>
|
|
724
684
|
|
|
725
685
|
Integrity data including permutation, secret, and proof
|
|
726
686
|
|