-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_zkPrepare.ts
120 lines (79 loc) · 2.82 KB
/
01_zkPrepare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import {getFullnodeUrl, SuiClient} from "@mysten/sui.js/client";
import {fromB64} from '@mysten/sui.js/utils';
import {Ed25519Keypair} from '@mysten/sui.js/keypairs/ed25519';
import {SUI_NETWORK} from "./config";
import {generateNonce, generateRandomness} from "@mysten/zklogin";
console.log("Connecting to SUI network: ", SUI_NETWORK);
const client = new SuiClient({
url: getFullnodeUrl("testnet"),
});
//Admin signer setup
let adminPrivateKeyArray = Uint8Array.from(Array.from(fromB64(process.env.ADMIN_SECRET_KEY!)));
const adminKeypair = Ed25519Keypair.fromSecretKey(adminPrivateKeyArray.slice(1));
const adminAddress = adminKeypair.getPublicKey().toSuiAddress();
console.log("Admin address: ", adminAddress);
async function doActions() {
const REDIRECT_URI = 'https://zklogin-dev-redirect.vercel.app/api/auth';
const params = new URLSearchParams({
// When using the provided test client ID + redirect site, the redirect_uri needs to be provided in the state.
state: new URLSearchParams({
redirect_uri: REDIRECT_URI
}).toString(),
// Test Client ID for devnet / testnet:
client_id: process.env.GOOGLE_DEV_CLIENT_ID!,
redirect_uri: REDIRECT_URI,
respond_type: 'id_token',
scope: 'openid',
// See below for details about generation of the nonce
nonce: 'nonce',
});
const loginURL = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
const currentEpoch = 124;//;await client.getCurrentEpoch();
const maxEpoch = 124 + 2;
const ephemeralKeyPair = new Ed25519Keypair();
const randomness = generateRandomness();
const nonce = generateNonce(ephemeralKeyPair.getPublicKey(), maxEpoch, randomness);
console.log("nonce = ", nonce);
}
doActions();
//
// async function executeTX() {
//
//
// const txb = new TransactionBlock();
// txb.setGasBudget(1000000000);
//
// client.signAndExecuteTransactionBlock({
// signer: adminKeypair,
// transactionBlock: txb,
// requestType: "WaitForLocalExecution",
// options: {
// showEffects: true,
// showObjectChanges: true,
// }
//
// }).then(res => {
// const status = res?.effects?.status.status;
//
// if (status === "success") {
// console.log("\r\n Status = ", status);
// console.log("Transaction digest = ", res?.digest, " ");
//
// res?.objectChanges?.find((obj) => {
// if (obj.type === "created" && obj.objectType.startsWith("AAA")) {
//
// }
// });
//
// }
// if (status == "failure") {
// console.log("Error = ", res?.effects);
// process.exit(1);
// }
//
// }).catch(error => {
// console.log(error);
// });
//
// }
//