예제 #1
0
    private IAuthClient CreateAuthClient()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            return(AuthClientFactory.Configure()
                   .WithLogger(Debug.unityLogger)
                   .WithClientId("25pDQvX4O5j7wgwT052Sh3UzXVR9X6Ud") // unity3d sdk
                   .WithDomain("loomx.auth0.com")
                   .WithScheme("io.loomx.unity3d")
                   .WithAudience("https://keystore.loomx.io/")
                   .WithScope("openid profile email picture")
                   .WithRedirectUrl("http://127.0.0.1:9998/auth/auth0/")
                   .Create());
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        return(AuthClientFactory.Configure()
               .WithLogger(Debug.unityLogger)
               .WithHostPageHandlers(new Loom.Unity3d.WebGL.HostPageHandlers
        {
            SignIn = "authenticateFromGame",
            GetUserInfo = "getUserInfo",
            SignOut = "clearUserInfo"
        })
               .Create());
#endif
    }
예제 #2
0
    public async void SignIn()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            var authClient  = this.CreateAuthClient();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await this.CreateKeyStore(accessToken);

            this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        var authClient = this.CreateAuthClient();
        this.identity = await authClient.GetIdentityAsync("", null);
#endif
        this.statusTextRef.text = "Signed in as " + this.identity.Username;

        var writer = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     .WithHTTP("http://127.0.0.1:46658/rpc")
                     //.WithWebSocket("ws://127.0.0.1:46657/websocket")
                     .Create();

        var reader = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     .WithHTTP("http://127.0.0.1:46658/query")
                     //.WithWebSocket("ws://127.0.0.1:47000/queryws")
                     .Create();

        var client = new DAppChainClient(writer, reader)
        {
            Logger = Debug.unityLogger
        };
        client.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[] {
            new NonceTxMiddleware {
                PublicKey = this.identity.PublicKey,
                Client    = client
            },
            new SignedTxMiddleware(this.identity.PrivateKey)
        });

        var contractAddr = await client.ResolveContractAddressAsync("BluePrint");

        var callerAddr = this.identity.ToAddress("default");
        this.contract = new Contract(client, contractAddr, callerAddr);
    }
예제 #3
0
    public async void SignIn()
    {
        try
        {
            CertValidationBypass.Enable();
            var authClient = AuthClientFactory.Configure()
                             .WithLogger(Debug.unityLogger)
                             .WithClientId("25pDQvX4O5j7wgwT052Sh3UzXVR9X6Ud") // unity3d sdk
                             .WithDomain("loomx.auth0.com")
                             .WithScheme("io.loomx.unity3d")
                             .WithAudience("https://keystore.loomx.io/")
                             .WithScope("openid profile email picture")
                             .WithRedirectUrl("http://127.0.0.1:9999/auth/auth0/")
                             .Create();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await KeyStoreFactory.CreateVaultStore(new VaultStoreConfig
            {
                Url         = "https://stage-vault.delegatecall.com/v1/",
                VaultPrefix = "unity3d-sdk",
                AccessToken = accessToken
            });

            this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
        this.statusTextRef.text = "Signed in as " + this.identity.Username;

        // This DAppChain client will connect to the example REST server in the Loom Go SDK.
        this.chainClient = new DAppChainClient("http://localhost", 46657, 47000)
        {
            Logger = Debug.unityLogger
        };
        this.chainClient.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[] {
            new NonceTxMiddleware {
                PublicKey = this.identity.PublicKey,
                Client    = this.chainClient
            },
            new SignedTxMiddleware(this.identity.PrivateKey)
        });
        this.callerAddr = this.identity.ToAddress("default");
    }
예제 #4
0
    public async void SignIn()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            var authClient  = this.CreateAuthClient();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await this.CreateKeyStore(accessToken);

            this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        var authClient = this.CreateAuthClient();
        this.identity = await authClient.GetIdentityAsync("", null);
#endif
        this.statusTextRef.text = "Signed in as " + this.identity.Username;
        // This DAppChain client will connect to the example REST server in the Loom Go SDK.
        var client = new DAppChainClient("http://localhost:46657", "http://localhost:47000")
        {
            Logger = Debug.unityLogger
        };
        client.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[] {
            new NonceTxMiddleware {
                PublicKey = this.identity.PublicKey,
                Client    = client
            },
            new SignedTxMiddleware(this.identity.PrivateKey)
        });

        // There is only one contract address at the moment...
        var contractAddr = Address.FromHexString("0x005B17864f3adbF53b1384F2E6f2120c6652F779");
        var callerAddr   = this.identity.ToAddress("default");
        this.contract = new Contract(client, contractAddr, "helloworld", callerAddr);
    }
예제 #5
0
    public async void ResetPrivateKey()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            var authClient  = this.CreateAuthClient();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await this.CreateKeyStore(accessToken);

            this.identity = await authClient.CreateIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        // TODO
        throw new NotImplementedException();
#endif
    }
예제 #6
0
    public async void SignIn()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            var authClient  = this.CreateAuthClient();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await this.CreateKeyStore(accessToken);

            this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        var authClient = this.CreateAuthClient();
        this.identity = await authClient.GetIdentityAsync("", null);
#endif
        this.statusTextRef.text = "Signed in as " + this.identity.Username;
    }
예제 #7
0
    public async void SignIn()
    {
        if (dAppChainCfg == null)
        {
            Start();
        }

        if (this.identity != null)
        {
            return;
        }
#if !UNITY_WEBGL
        if (PlayerPrefs.GetString("identityString") == "" && PlayerPrefs.GetString("usernameString") == "")
        {
            try
            {
                CertValidationBypass.Enable();
                var authClient  = this.CreateAuthClient();
                var accessToken = await authClient.GetAccessTokenAsync();

                var keyStore = await this.CreateKeyStore(accessToken);

                this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
            }
            finally
            {
                CertValidationBypass.Disable();
            }
        }
        else
        {
            this.identity = new Identity {
                Username   = PlayerPrefs.GetString("usernameString"),
                PrivateKey = CryptoUtils.HexStringToBytes(PlayerPrefs.GetString("identityString"))
            };
        }
#else
        var authClient = this.CreateAuthClient();
        this.identity = await authClient.GetIdentityAsync("", null);
#endif

        PlayerPrefs.SetString("identityString", CryptoUtils.BytesToHexString(this.identity.PrivateKey));
        PlayerPrefs.SetString("usernameString", this.identity.Username);

        var writer = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     .WithHTTP(dAppChainCfg.write_host)
                     //.WithWebSocket("ws://etherboy-stage.loomapps.io/websocket")
                     .Create();

        var reader = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     .WithHTTP(dAppChainCfg.read_host)
                     //.WithWebSocket("ws://etherboy-stage.loomapps.io/queryws")
                     .Create();

        var client = new DAppChainClient(writer, reader)
        {
            Logger = Debug.unityLogger
        };
        client.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[] {
            new NonceTxMiddleware {
                PublicKey = this.identity.PublicKey,
                Client    = client
            },
            new SignedTxMiddleware(this.identity.PrivateKey)
        });

        // There is only one contract address at the moment...
        var contractAddr = Address.FromHexString("0xe288d6eec7150D6a22FDE33F0AA2d81E06591C4d");
        var callerAddr   = this.identity.ToAddress("default");
        this.contract = new Contract(client, contractAddr, callerAddr);

        //call create account, if it's a new user, an account will be created for Etherboy
        if (PlayerPrefs.GetInt("hasAccount") == 0)
        {
            CreateAccount();
        }
    }
예제 #8
0
    public async void SignIn()
    {
#if !UNITY_WEBGL
        try
        {
            CertValidationBypass.Enable();
            var authClient  = this.CreateAuthClient();
            var accessToken = await authClient.GetAccessTokenAsync();

            var keyStore = await this.CreateKeyStore(accessToken);

            this.identity = await authClient.GetIdentityAsync(accessToken, keyStore);
        }
        finally
        {
            CertValidationBypass.Disable();
        }
#else
        var authClient = this.CreateAuthClient();
        this.identity = await authClient.GetIdentityAsync("", null);
#endif
        this.statusTextRef.text = "Signed in as " + this.identity.Username;

        var writer = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     //.WithHTTP("http://127.0.0.1:46658/rpc")
                     .WithWebSocket("ws://127.0.0.1:46657/websocket")
                     .Create();

        var reader = RPCClientFactory.Configure()
                     .WithLogger(Debug.unityLogger)
                     //.WithHTTP("http://127.0.0.1:46658/query")
                     .WithWebSocket("ws://127.0.0.1:9999/queryws")
                     .Create();

        var client = new DAppChainClient(writer, reader)
        {
            Logger = Debug.unityLogger
        };
        client.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[] {
            new NonceTxMiddleware {
                PublicKey = this.identity.PublicKey,
                Client    = client
            },
            new SignedTxMiddleware(this.identity.PrivateKey)
        });

        var contractAddr = await client.ResolveContractAddressAsync("BluePrint");

        var callerAddr = this.identity.ToAddress("default");
        this.contract = new Contract(client, contractAddr, callerAddr);

        // Subscribe to DAppChainClient.OnChainEvent to receive all events

        /*
         * client.OnChainEvent += (sender, e) =>
         * {
         *  var jsonStr = System.Text.Encoding.UTF8.GetString(e.Data);
         *  var data = JsonConvert.DeserializeObject<SampleEvent>(jsonStr);
         *  Debug.Log(string.Format("Chain Event: {0}, {1}, {2} from block {3}", data.Method, data.Key, data.Value, e.BlockHeight));
         * };
         */

        // Subscribe to DAppChainClient.OnEvent to receive events from a specific smart contract
        this.contract.OnEvent += (sender, e) =>
        {
            var jsonStr = System.Text.Encoding.UTF8.GetString(e.Data);
            var data    = JsonConvert.DeserializeObject <SampleEvent>(jsonStr);
            Debug.Log(string.Format("Contract Event: {0}, {1}, {2} from block {3}", data.Method, data.Key, data.Value, e.BlockHeight));
        };
    }