suidouble 0.0.49 → 0.0.50

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/lib/SuiMaster.js CHANGED
@@ -13,7 +13,7 @@ const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
13
13
  const { Secp256r1Keypair } = require('@mysten/sui.js/keypairs/secp256r1');
14
14
  const { Secp256k1Keypair } = require('@mysten/sui.js/keypairs/secp256k1');
15
15
  const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet');
16
- const { TransactionBlock,Transactions } = require('@mysten/sui.js/transactions');
16
+ const { TransactionBlock, Transactions } = require('@mysten/sui.js/transactions');
17
17
 
18
18
  class SuiMaster extends SuiCommonMethods {
19
19
  constructor(params = {}) {
@@ -0,0 +1,39 @@
1
+ const { generateNonce, generateRandomness } = require('@mysten/zklogin');
2
+ const SuiCommonMethods = require('./SuiCommonMethods.js');
3
+ const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
4
+
5
+ class SuidoubleZKLogin extends SuiCommonMethods {
6
+ constructor(params = {}) {
7
+ super(params);
8
+ this._suiMaster = params.suiMaster;
9
+ if (!this._suiMaster) {
10
+ throw new Error('suiMaster is required');
11
+ }
12
+
13
+ this._clientId = '623255759333-fr0ijf03itgc4t70e8aj99iud9lnsuqm.apps.googleusercontent.com';
14
+ }
15
+
16
+ async getNonce() {
17
+ const client = this._suiMaster.provider;
18
+ const { epoch, epochDurationMs, epochStartTimestampMs } = await client.getLatestSuiSystemState();
19
+ const maxEpoch = Number(epoch) + 2; // this means the ephemeral key will be active for 2 epochs from now.
20
+ const randomness = generateRandomness();
21
+
22
+ const ephemeralKeyPair = new Ed25519Keypair();
23
+ const nonce = generateNonce(ephemeralKeyPair.getPublicKey(), maxEpoch, randomness);
24
+
25
+ return nonce;
26
+ }
27
+
28
+ async getOAuthURL(params = {}) {
29
+ const redirectURL = params.redirectURL;
30
+
31
+ const nonce = await this.getNonce();
32
+ const url = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${this._clientId}&response_type=id_token&redirect_uri=${redirectURL}&scope=openid&nonce=${nonce}`;
33
+
34
+ return url;
35
+ }
36
+
37
+ }
38
+
39
+ module.exports = SuidoubleZKLogin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,7 +21,8 @@
21
21
  "author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@mysten/sui.js": "^0.42.0",
24
+ "@mysten/sui.js": "^0.43.3",
25
+ "@mysten/zklogin": "^0.1.8",
25
26
  "@wallet-standard/core": "^1.0.3"
26
27
  },
27
28
  "devDependencies": {