diff --git a/Plugins/Android.meta b/Plugins/Android.meta new file mode 100644 index 000000000..fc5fa6cfd --- /dev/null +++ b/Plugins/Android.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9cd23c71d0d4141a59629350b89f6e29 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/AsyncAwaitUtil.meta b/Plugins/AsyncAwaitUtil.meta new file mode 100644 index 000000000..8951b2c4e --- /dev/null +++ b/Plugins/AsyncAwaitUtil.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0350ae9d108f347bcaeb75bf8495bee7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/BouncyCastle.Crypto.dll.meta b/Plugins/BouncyCastle.Crypto.dll.meta new file mode 100644 index 000000000..bc69d1505 --- /dev/null +++ b/Plugins/BouncyCastle.Crypto.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 17dc4421bf4c5904889f88e8430c8715 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Jint.meta b/Plugins/Jint.meta new file mode 100644 index 000000000..67fd4be4f --- /dev/null +++ b/Plugins/Jint.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 74e40aac20e02b54097149bcc1376450 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Nethereum.meta b/Plugins/Nethereum.meta new file mode 100644 index 000000000..eb3b1e116 --- /dev/null +++ b/Plugins/Nethereum.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27dfa56d2a486d744a3ecae1bd803e89 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab b/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab new file mode 100644 index 000000000..a67b134c6 --- /dev/null +++ b/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7939348423131755349 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1857326031979140900} + - component: {fileID: 5699726257888795520} + m_Layer: 0 + m_Name: SignVerifyPK + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1857326031979140900 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7939348423131755349} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &5699726257888795520 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7939348423131755349} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f9259fdff3465734daf9219e118083ce, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab.meta b/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab.meta new file mode 100644 index 000000000..6658d7f78 --- /dev/null +++ b/Web3Unity/Prefabs/PrivateKey/SignVerifyPK.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e88c32763c262834184348e948fb4e68 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab b/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab new file mode 100644 index 000000000..1c62a8fc8 --- /dev/null +++ b/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2774818338625932009 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2774818338625932010} + - component: {fileID: 3278632383507343372} + m_Layer: 0 + m_Name: SignVerifyWebWallet + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2774818338625932010 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2774818338625932009} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &3278632383507343372 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2774818338625932009} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 22b7ebb5b91e09b4fa5c2911cefd95c5, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab.meta b/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab.meta new file mode 100644 index 000000000..7d7e0b3a8 --- /dev/null +++ b/Web3Unity/Prefabs/Wallet/SignVerifyWebWallet.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: edabd3e66397ee3468368d3b617e6b18 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Web3Unity/Prefabs/WebGL/SignVerifyExample.prefab b/Web3Unity/Prefabs/WebGL/SignVerifyExample.prefab index b211aaeaa..a49a03a1f 100644 --- a/Web3Unity/Prefabs/WebGL/SignVerifyExample.prefab +++ b/Web3Unity/Prefabs/WebGL/SignVerifyExample.prefab @@ -116,7 +116,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 23, y: -48} + m_AnchoredPosition: {x: 23, y: -13} m_SizeDelta: {x: 160, y: 30} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &2799717858554657643 @@ -225,7 +225,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3c19034a790b61441adfd1dffc88b51c, type: 3} m_Name: m_EditorClassIdentifier: - message: hello + message: hello1 textHashedMessage: {fileID: 7523017095230044065} textSignedHash: {fileID: 7303377407210195607} verifyAddress: {fileID: 6576852011596053091} @@ -295,7 +295,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 39.013, y: -153} + m_AnchoredPosition: {x: 39.013, y: -70} m_SizeDelta: {x: 514.96, y: 30} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1190075119736674779 diff --git a/Web3Unity/Scripts/Library/Web3PrivateKey.cs b/Web3Unity/Scripts/Library/Web3PrivateKey.cs index e7bab99bd..e1d627faa 100755 --- a/Web3Unity/Scripts/Library/Web3PrivateKey.cs +++ b/Web3Unity/Scripts/Library/Web3PrivateKey.cs @@ -41,8 +41,7 @@ public static string Address(string _privateKey) public static string Sign(string _privateKey, string _message) { var signer = new EthereumMessageSigner(); - EthECKey key = new EthECKey(_privateKey); - string signature = signer.EncodeUTF8AndSign(_message, new EthECKey(_privateKey)); + string signature = signer.HashAndSign(_message, _privateKey); return signature; } } \ No newline at end of file diff --git a/Web3Unity/Scripts/Library/Web3Wallet.cs b/Web3Unity/Scripts/Library/Web3Wallet.cs index 87513b1fe..bb10538bf 100644 --- a/Web3Unity/Scripts/Library/Web3Wallet.cs +++ b/Web3Unity/Scripts/Library/Web3Wallet.cs @@ -1,5 +1,8 @@ using System; +using System.Runtime.InteropServices; using System.Threading.Tasks; +using Nethereum.Hex.HexConvertors.Extensions; +using Nethereum.Signer; using UnityEngine; using Nethereum.Util; @@ -62,9 +65,9 @@ public static async Task Sign(string _message) public static string Sha3(string _message) { - Sha3Keccack hasher = new Sha3Keccack(); - string hash = hasher.CalculateHash(_message); - // 0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8 - return "0x" + hash; + var signer = new EthereumMessageSigner(); + var hash = new Sha3Keccack().CalculateHash(_message).EnsureHexPrefix(); + // 0x06b3dfaec148fb1bb2b066f10ec285e7c9bf402ab32aa78a5d38e34566810cd2 + return hash; } } diff --git a/Web3Unity/Scripts/Library/WebGL/Web3GL.cs b/Web3Unity/Scripts/Library/WebGL/Web3GL.cs index d23efa97a..9655ffd54 100644 --- a/Web3Unity/Scripts/Library/WebGL/Web3GL.cs +++ b/Web3Unity/Scripts/Library/WebGL/Web3GL.cs @@ -169,5 +169,4 @@ public static int Network() } } - #endif diff --git a/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet.cs b/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet.cs index b99d05cf7..3937e37e7 100644 --- a/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet.cs +++ b/Web3Unity/Scripts/Prefabs/Minter/MintWeb3Wallet.cs @@ -8,25 +8,30 @@ public class MintWeb3Wallet : MonoBehaviour public string chain = "ethereum"; public string network = "rinkeby"; // mainnet ropsten kovan rinkeby goerli - public string account = PlayerPrefs.GetString("Account"); + public string account; public string to = "0x7259E32e35cf880aEACfbD412E7F4Baa8606e04c"; public string cid = "QmXjWjjMU8r39UCEZ8483aNedwNRFRLvvV9kwq1GpCgthj"; public string chainId = "4"; - + public void Start() + { + account = PlayerPrefs.GetString("Account"); + } + // Start is called before the first frame update public async void MintNFT() { CreateMintModel.Response nftResponse = await EVM.CreateMint(chain, network, account, to, cid); Debug.Log("NFT Response: " + nftResponse); + account = PlayerPrefs.GetString("Account"); // connects to user's browser wallet (metamask) to send a transaction try { string response = await Web3Wallet.SendTransaction(chainId, nftResponse.tx.to, nftResponse.tx.value, nftResponse.tx.data, nftResponse.tx.gasLimit, nftResponse.tx.gasPrice); + print(response); Debug.Log(response); } catch (Exception e) { Debug.LogException(e, this); } - } } diff --git a/Web3Unity/Scripts/Prefabs/Minter/MintWebGL.cs b/Web3Unity/Scripts/Prefabs/Minter/MintWebGL.cs index a634f866c..c0e8b94ac 100644 --- a/Web3Unity/Scripts/Prefabs/Minter/MintWebGL.cs +++ b/Web3Unity/Scripts/Prefabs/Minter/MintWebGL.cs @@ -11,17 +11,22 @@ public class MintWebGL : MonoBehaviour // Start is called before the first frame update public string chain = "ethereum"; public string network = "rinkeby"; // mainnet ropsten kovan rinkeby goerli - public string account = "0x148dC439Ffe10DF915f1DA14AA780A47A577709E"; + public string account; public string to = "0x148dC439Ffe10DF915f1DA14AA780A47A577709E"; public string cid = "QmXjWjjMU8r39UCEZ8483aNedwNRFRLvvV9kwq1GpCgthj"; - - + + + public void Start() + { + account = PlayerPrefs.GetString("Account"); + } + public async void MintNFT() { CreateMintModel.Response nftResponse = await EVM.CreateMint(chain, network, account, to, cid); // connects to user's browser wallet (metamask) to send a transaction try - { + { string response = await Web3GL.SendTransactionData(nftResponse.tx.to, nftResponse.tx.value, nftResponse.tx.gasPrice,nftResponse.tx.gasLimit, nftResponse.tx.data); print("Response: " + response); } catch (Exception e) { diff --git a/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs b/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs new file mode 100644 index 000000000..b7099d0d6 --- /dev/null +++ b/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using Nethereum.Hex.HexConvertors.Extensions; +using UnityEngine; + +public class SignVerifyPK : MonoBehaviour +{ + // Start is called before the first frame update + async void Start() + { + var privateKey = "ADD_PRIVATE_KEY"; + string message = "hello"; + var hashedMessage = Web3Wallet.Sha3(message); + Debug.Log("Hashed Message PK: " + hashedMessage); + string signature = Web3PrivateKey.Sign(privateKey, message); + print("Signature PK: " + signature); + // get account from private key + string account = Web3PrivateKey.Address(privateKey); + print("Account from PK: " + account); + string address = await EVM.Verify(hashedMessage, signature); + print("Address From Verify PK: " + address); + + ParseSignatureFunction(signature); + } + // Update is called once per frame + public void ParseSignatureFunction(string sig) + { + string signature = sig; + string r = signature.Substring(0, 66).EnsureHexPrefix(); + Debug.Log("PK R:" + r); + string s = signature.Substring(66, 64).EnsureHexPrefix(); + Debug.Log("PK S: " + s); + int v = int.Parse(signature.Substring(130, 2), System.Globalization.NumberStyles.HexNumber); + Debug.Log("PK V: " + v); + } +} \ No newline at end of file diff --git a/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs.meta b/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs.meta new file mode 100644 index 000000000..6dc126a06 --- /dev/null +++ b/Web3Unity/Scripts/Prefabs/PrivateKey/SignVerifyPK.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f9259fdff3465734daf9219e118083ce +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs b/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs new file mode 100644 index 000000000..2f1c3b4e9 --- /dev/null +++ b/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs @@ -0,0 +1,28 @@ +using System.Text; +using Nethereum.Signer; +using Nethereum.Util; +using UnityEngine; + +public class SignVerifyWebWallet : MonoBehaviour +{ + // Start is called before the first frame update + async void Start() + { + string message = "hello"; + string signature = await Web3Wallet.Sign(message); + //verification + SignVerifySignature(signature, message); + } + + public void SignVerifySignature(string signatureString, string originalMessage) + { + string msg = "\x19" + "Ethereum Signed Message:\n" + originalMessage.Length + originalMessage; + byte[] msgHash = new Sha3Keccack().CalculateHash(Encoding.UTF8.GetBytes(msg)); + EthECDSASignature signature = MessageSigner.ExtractEcdsaSignature(signatureString); + EthECKey key = EthECKey.RecoverFromSignature(signature, msgHash); + + bool isValid = key.Verify(msgHash, signature); + Debug.Log("Address Returned: " + key.GetPublicAddress()); + Debug.Log("Is Valid: " + isValid); + } +} diff --git a/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs.meta b/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs.meta new file mode 100644 index 000000000..30ed83291 --- /dev/null +++ b/Web3Unity/Scripts/Prefabs/Wallet/SignVerifyWebWallet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 22b7ebb5b91e09b4fa5c2911cefd95c5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignVerifyExample.cs b/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignVerifyExample.cs index edbc1dfe5..7c64fb2da 100644 --- a/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignVerifyExample.cs +++ b/Web3Unity/Scripts/Prefabs/WebGL/WebGLSignVerifyExample.cs @@ -9,7 +9,7 @@ public class WebGLSignVerifyExample : MonoBehaviour { - public string message = "hello1"; + public string message = "hello"; public Text textHashedMessage; public Text textSignedHash; public Text verifyAddress; diff --git a/WebGLTemplates/Web3GL-2020x/network.js b/WebGLTemplates/Web3GL-2020x/network.js index a43b7a4f4..5128d753b 100644 --- a/WebGLTemplates/Web3GL-2020x/network.js +++ b/WebGLTemplates/Web3GL-2020x/network.js @@ -20,7 +20,6 @@ Used to set the network: https://chainlist.org/ 1666600000 Harmony Mainnet Shard0 25 Cronos Mainnet Beta 338 Cronos Testnet -71401 Nervos EVM Layer Godworken v1.1 */ window.web3ChainId = 4;