diff --git a/native-apps/unity_ii_applink/README.md b/native-apps/unity_ii_applink/README.md index 8880d7407..1c1fafe35 100644 --- a/native-apps/unity_ii_applink/README.md +++ b/native-apps/unity_ii_applink/README.md @@ -11,15 +11,22 @@ This is a Unity project with [ICP.NET](https://github.com/BoomDAO/ICP.NET) embed ## Workflow Before continuing, please read through the [Android App Links](https://developer.android.com/studio/write/app-link-indexing) to understand how Android App Links works. -Here is the basic workflow that how to integrate with Internet Identity from a Unity Android game. The basic idea is to open the Web Browser from the game, login in with II in the browser, and pass the DelegationIdentity back to the game. +Here is the basic workflow that how to integrate with Internet Identity from a Unity Android game. The basic idea is to open the Web Browser from the game, login in with II in the browser, and pass the `DelegationChain` back to the game. The steps in detail are described below: 1. Set up an [Internet Identity integration dapp](#ii_integration_dapp) which supports logging in with II, with an `assetlinks.json` file associated. Please refer to [ii_integration_dapp](./ii_integration_dapp/README.md) to set up the dapp. + 2. Run a Unity game on Android, which is built from [android_integration sample](#unity_project). Please refer to [unity_project](./unity_project/README.md) to build the Unity Android game. + 3. Launch the Web Browser from the game to open the dapp frontend deployed in #1, with the public key of `Ed25519Identity` as a parameter. + 4. Login with your Internet Identity in the Web Browser. -5. Launch the application via App Links, and pass the `DelegationIdentity` back to the game as the URL parameter. -6. Call the backend canister with the `DelegationIdentity` to greet. + +5. Launch the application via App Links, and pass the `DelegationChain` back to the game as the URL parameter. + +6. Composite the `DelegationIdentity` with `DelegationChain` and the `Ed25519Identity`. + +7. Call the backend canister with the `DelegationIdentity` to greet. diff --git a/native-apps/unity_ii_applink/ii_integration_dapp/README.md b/native-apps/unity_ii_applink/ii_integration_dapp/README.md index 4592266ea..f16c221ba 100644 --- a/native-apps/unity_ii_applink/ii_integration_dapp/README.md +++ b/native-apps/unity_ii_applink/ii_integration_dapp/README.md @@ -4,13 +4,15 @@ This example derives from the [internet_identity_integration](https://github.com ## Overview -This example shows a special case to support login with the `IncompleteEd25519KeyIdentity` which only contains the public key. The reason why we support this is all for security. +This example shows a use case to support login with the two delegations on the `DelegationChain`. As we described in [Internet Identity Integration](../README.md#workflow), users can log in with II from the game. Usually what they do is 1. Generate the `Ed25519KeyIdentity` supported by [ICP.NET](https://github.com/BoomDAO/ICP.NET) in the Unity game. -2. For security purposes, only pass the public key of the `Ed25519KeyIdentity` to the Web browser for login, this is where `IncompleteEd25519KeyIdentity` can be used for. -3. In [index.js](./src/greet_frontend/src/index.js), we describe how to retrieve the public key of the `Ed25519Identity` from the URL parameter, use it to instantiate an `IncompleteEd25519KeyIdentity`, and log in with Internet Identity. +2. For security purposes, only pass the public key of the `Ed25519KeyIdentity` to the Web browser for login. And only the public key is necessary when creating a `DelegationChain`. +3. In [index.js](./src/greet_frontend/src/index.js), we describe how to + - log in with Internet Identity with the frontend generated session key + - retrieve the public key of the `Ed25519Identity` from the URL parameter and create another delegation with it. With this, users don't need to pass the private key around, also they don't need to store the private key outside of the game as they can regenerate the key pairs for every session. diff --git a/native-apps/unity_ii_applink/ii_integration_dapp/canister_ids.json b/native-apps/unity_ii_applink/ii_integration_dapp/canister_ids.json new file mode 100644 index 000000000..6b0f9fa0c --- /dev/null +++ b/native-apps/unity_ii_applink/ii_integration_dapp/canister_ids.json @@ -0,0 +1,8 @@ +{ + "greet_backend": { + "ic": "72rj2-biaaa-aaaan-qdatq-cai" + }, + "greet_frontend": { + "ic": "6x7nu-oaaaa-aaaan-qdaua-cai" + } +} \ No newline at end of file diff --git a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/assets/.well-known/assetlinks.json b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/assets/.well-known/assetlinks.json index 49a4f1c11..88d52e098 100644 --- a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/assets/.well-known/assetlinks.json +++ b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/assets/.well-known/assetlinks.json @@ -2,8 +2,8 @@ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", - "package_name": "com.DefaultCompany.II_AppLink_Integration", + "package_name": "com.dfinity.ii_applink_integration", "sha256_cert_fingerprints": - ["86:C9:CA:6F:5A:53:7E:75:9C:D7:29:1E:8A:94:90:BE:90:0B:02:12:40:45:19:B6:65:84:3C:02:AB:B5:97:14"] + ["A3:E2:36:BC:E9:04:3F:8F:A9:C5:9B:B5:FE:89:95:C8:08:BA:35:2D:07:D8:76:13:65:A9:27:D6:33:6B:44:6E"] } }] \ No newline at end of file diff --git a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.html b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.html index b2c95ec09..93b7e0415 100644 --- a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.html +++ b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.html @@ -21,6 +21,10 @@
+
+ +
+
diff --git a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.js b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.js index 11f07a6c0..c67c32cec 100644 --- a/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.js +++ b/native-apps/unity_ii_applink/ii_integration_dapp/src/greet_frontend/src/index.js @@ -1,47 +1,30 @@ -import {AuthClient} from "@dfinity/auth-client" -import {SignIdentity} from "@dfinity/agent"; -import {DelegationIdentity, Ed25519PublicKey } from "@dfinity/identity"; - -// An incomplete Ed25519KeyIdentity with only the public key provided. -class IncompleteEd25519KeyIdentity extends SignIdentity { - constructor(publicKey) { - super(); - this._publicKey = publicKey; - } - - getPublicKey () { - return this._publicKey; - } -} - -function fromHexString(hexString) { - return new Uint8Array((hexString.match(/.{1,2}/g) ?? []).map(byte => parseInt(byte, 16))).buffer; -} +import {createActor, greet_backend} from "../../declarations/greet_backend"; +import {AuthClient} from "@dfinity/auth-client"; +import {HttpAgent} from "@dfinity/agent"; +import {DelegationIdentity, Ed25519PublicKey, ECDSAKeyIdentity, DelegationChain} from "@dfinity/identity"; +import {fromHexString} from "@dfinity/identity/lib/cjs/buffer"; -let myKeyIdentity; -let sessionKeyIndex = -1; +let appPublicKey; var url = window.location.href; -sessionKeyIndex = url.indexOf("sessionkey="); -if (sessionKeyIndex !== -1) { - // Parse the public session key and instantiate an IncompleteEd25519KeyIdentity. - var sessionkey = url.substring(sessionKeyIndex + "sessionkey=".length); - - var publicKey = Ed25519PublicKey.fromDer(fromHexString(sessionkey)); - myKeyIdentity = new IncompleteEd25519KeyIdentity(publicKey); -} else { - // TODO: initialize an Ed25519KeyIdentity(); +var publicKeyIndex = url.indexOf("sessionkey="); +if (publicKeyIndex !== -1) { + // Parse the public key. + var publicKeyString = url.substring(publicKeyIndex + "sessionkey=".length); + appPublicKey = Ed25519PublicKey.fromDer(fromHexString(publicKeyString)); } -let delegationIdentity; +let actor = greet_backend; +let delegationChain; const loginButton = document.getElementById("login"); loginButton.onclick = async (e) => { e.preventDefault(); // Create an auth client. + var middleKeyIdentity = await ECDSAKeyIdentity.generate(); let authClient = await AuthClient.create({ - identity: myKeyIdentity, + identity: middleKeyIdentity, }); // Start the login process and wait for it to finish. @@ -53,9 +36,24 @@ loginButton.onclick = async (e) => { }); // At this point we're authenticated, and we can get the identity from the auth client. - const identity = authClient.getIdentity(); - if (identity instanceof DelegationIdentity) { - delegationIdentity = identity; + const middleIdentity = authClient.getIdentity(); + + // Using the identity obtained from the auth client to create an agent to interact with the IC. + const agent = new HttpAgent({identity: middleIdentity}); + actor = createActor(process.env.GREET_BACKEND_CANISTER_ID, { + agent, + }); + + // Create another delegation with the app public key, then we have two delegations on the chain. + if (appPublicKey != null && middleIdentity instanceof DelegationIdentity ) { + let middleToApp = await DelegationChain.create( + middleKeyIdentity, + appPublicKey, + new Date(Date.now() + 15 * 60 * 1000), + { previous: middleIdentity.getDelegation() }, + ); + + delegationChain = middleToApp; } return false; @@ -65,19 +63,33 @@ const openButton = document.getElementById("open"); openButton.onclick = async (e) => { e.preventDefault(); - // if (sessionKeyIndex === -1) { - // // TODO: warning for not login from a game. - // return false; - // } + if (delegationChain == null){ + console.log("Invalid delegation chain."); + return false; + } var url = "https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io/authorize?"; - if (delegationIdentity != null) { - var delegationString = JSON.stringify(delegationIdentity.getDelegation().toJSON()); - console.log(delegationString); - url = url + "delegation=" + encodeURIComponent(delegationString); - } + var delegationString = JSON.stringify(delegationChain.toJSON()); + url = url + "delegation=" + encodeURIComponent(delegationString); + //console.log(url); window.open(url, "_self"); return false; }; + +const greetButton = document.getElementById("greet"); +greetButton.onclick = async (e) => { + e.preventDefault(); + + greetButton.setAttribute("disabled", true); + + // Interact with backend actor, calling the greet method + const greeting = await actor.greet(); + + greetButton.removeAttribute("disabled"); + + document.getElementById("greeting").innerText = greeting; + + return false; +}; diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll new file mode 100644 index 000000000..6ddfa6c5a Binary files /dev/null and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta similarity index 93% rename from native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta rename to native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta index 3a5357487..13f6d5ca5 100644 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f745e12d1a54fa048b17f8a755aee668 +guid: 593489fde6eec1d409339f2068027223 PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll deleted file mode 100644 index 99a22be95..000000000 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll and /dev/null differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll deleted file mode 100644 index 0181013b5..000000000 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll and /dev/null differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll deleted file mode 100644 index af1d6a3d0..000000000 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll and /dev/null differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta deleted file mode 100644 index e1dba25b7..000000000 --- a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta +++ /dev/null @@ -1,33 +0,0 @@ -fileFormatVersion: 2 -guid: 5ee3fda08d13e3d498234a64d78a5fb4 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - 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/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll index 3a93d8125..9d1a43d52 100644 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll new file mode 100644 index 000000000..b8f114d09 Binary files /dev/null and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta similarity index 93% rename from native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta rename to native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta index 3a5357487..c7e3eca2e 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll.meta +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f745e12d1a54fa048b17f8a755aee668 +guid: 933c2d47759680543a7661c61b41b2ae PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll index 4f3f4e039..6b7348be6 100644 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md new file mode 100644 index 000000000..b13d4ca7b --- /dev/null +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md @@ -0,0 +1,6 @@ +# ICP.NET + +The libraries in ICP.NET are built from https://github.com/BoomDAO/ICP.NET, with + +1. Version `4.0.0`, hashtag `7b51d78b4f4356d767bb86074918a41973c41214`. +2. `ByteUtil` class is changed from `internal` to `public` in `\ICP.NET\src\Candid\Utilities\ByteUtil.cs` file. diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md.meta new file mode 100644 index 000000000..b31a6325d --- /dev/null +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4f04216d2bad9a94cb9378defe463e06 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll deleted file mode 100644 index 98774b92a..000000000 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll and /dev/null differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta deleted file mode 100644 index 34b4429c9..000000000 --- a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta +++ /dev/null @@ -1,27 +0,0 @@ -fileFormatVersion: 2 -guid: 07c068288c2d9674baf2713ade0ce777 -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 - userData: - assetBundleName: - assetBundleVariant: diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll new file mode 100644 index 000000000..f2e77b766 Binary files /dev/null and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta similarity index 93% rename from native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta rename to native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta index bc19e5959..d633142ea 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ce5b0ae0fccda8548aaf3ae7c72c5758 +guid: b7149630e9d423f43bbeaf40e8c86807 PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll deleted file mode 100644 index 5a41247f7..000000000 Binary files a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll and /dev/null differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll new file mode 100644 index 000000000..b8190e265 Binary files /dev/null and b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll differ diff --git a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta similarity index 93% rename from native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta rename to native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta index 4c337afdf..7d89f570c 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta +++ b/native-apps/unity_ii_applink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2762ae604c55d504b973b2b9a472f2a4 +guid: 471526ac3bbfe74498c79e74a8c37986 PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/native-apps/unity_ii_applink/unity_project/Assets/Scenes/SampleScene.unity b/native-apps/unity_ii_applink/unity_project/Assets/Scenes/SampleScene.unity index 9f68ff852..78d6cfd78 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/Scenes/SampleScene.unity +++ b/native-apps/unity_ii_applink/unity_project/Assets/Scenes/SampleScene.unity @@ -168,6 +168,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5c68e31d1a87467468d62c1cd739b0a0, type: 3} m_Name: m_EditorClassIdentifier: + greetFrontend: https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io/ greetBackendCanister: 72rj2-biaaa-aaaan-qdatq-cai --- !u!114 &272906662 MonoBehaviour: @@ -181,7 +182,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 17feafab2ee1b6b4684003f4b0edc397, type: 3} m_Name: m_EditorClassIdentifier: - greetFrontend: https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io --- !u!1 &671559154 GameObject: m_ObjectHideFlags: 0 diff --git a/native-apps/unity_ii_applink/unity_project/Assets/Scripts/DeepLinkPlugin.cs b/native-apps/unity_ii_applink/unity_project/Assets/Scripts/DeepLinkPlugin.cs index 7e297d3d2..8b5b92cae 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/Scripts/DeepLinkPlugin.cs +++ b/native-apps/unity_ii_applink/unity_project/Assets/Scripts/DeepLinkPlugin.cs @@ -1,7 +1,13 @@ using UnityEngine; +using EdjCase.ICP.Agent; +using EdjCase.ICP.Agent.Identities; +using EdjCase.ICP.Agent.Models; +using EdjCase.ICP.Candid.Models; using EdjCase.ICP.Candid.Utilities; using Newtonsoft.Json; +using System; using System.Web; +using System.Collections.Generic; namespace IC.GameKit { @@ -22,7 +28,7 @@ public void Start() public void OpenBrowser() { - var target = mTestICPAgent.greetFrontend + "?sessionkey=" + ByteUtil.ToHexString(mTestICPAgent.TestIdentity.PublicKey.Value); + var target = mTestICPAgent.greetFrontend + "?sessionkey=" + ByteUtil.ToHexString(mTestICPAgent.TestIdentity.PublicKey.ToDerEncoding()); Application.OpenURL(target); } @@ -40,8 +46,36 @@ public void OnDeepLinkActivated(string url) } var delegationString = HttpUtility.UrlDecode(url.Substring(indexOfDelegation + kDelegationParam.Length)); - var delegation = JsonConvert.DeserializeObject(delegationString); - mTestICPAgent.Delegation = delegation; + mTestICPAgent.DelegationIdentity = ConvertJsonToDelegationIdentity(delegationString); + } + + internal DelegationIdentity ConvertJsonToDelegationIdentity(string jsonDelegation) + { + var delegationChainModel = JsonConvert.DeserializeObject(jsonDelegation); + if (delegationChainModel == null && delegationChainModel.delegations.Length == 0) + { + Debug.LogError("Invalid delegation chain."); + return null; + } + + // Initialize DelegationIdentity. + var delegations = new List(); + foreach (var signedDelegationModel in delegationChainModel.delegations) + { + var pubKey = SubjectPublicKeyInfo.FromDerEncoding(ByteUtil.FromHexString(signedDelegationModel.delegation.pubkey)); + var expiration = ICTimestamp.FromNanoSeconds(Convert.ToUInt64(signedDelegationModel.delegation.expiration, 16)); + var delegation = new Delegation(pubKey, expiration); + + var signature = ByteUtil.FromHexString(signedDelegationModel.signature); + var signedDelegation = new SignedDelegation(delegation, signature); + delegations.Add(signedDelegation); + } + + var chainPublicKey = SubjectPublicKeyInfo.FromDerEncoding(ByteUtil.FromHexString(delegationChainModel.publicKey)); + var delegationChain = new DelegationChain(chainPublicKey, delegations); + var delegationIdentity = new DelegationIdentity(mTestICPAgent.TestIdentity, delegationChain); + + return delegationIdentity; } } } diff --git a/native-apps/unity_ii_applink/unity_project/Assets/Scripts/TestICPAgent.cs b/native-apps/unity_ii_applink/unity_project/Assets/Scripts/TestICPAgent.cs index 98c60208a..c37baa2d6 100644 --- a/native-apps/unity_ii_applink/unity_project/Assets/Scripts/TestICPAgent.cs +++ b/native-apps/unity_ii_applink/unity_project/Assets/Scripts/TestICPAgent.cs @@ -1,13 +1,8 @@ using UnityEngine; using UnityEngine.UI; -using EdjCase.ICP.Agent; using EdjCase.ICP.Agent.Agents; using EdjCase.ICP.Agent.Identities; using EdjCase.ICP.Candid.Models; -using EdjCase.ICP.Candid.Utilities; -using System.Collections.Generic; -using EdjCase.ICP.Agent.Models; -using System; namespace IC.GameKit { @@ -19,17 +14,18 @@ public class TestICPAgent : MonoBehaviour Text mMyPrincipalText = null; Button mGreetButton = null; Ed25519Identity mEd25519Identity = null; - DelegationChainModel mDelegation = null; + DelegationIdentity mDelegationIdentity = null; public Ed25519Identity TestIdentity { get { return mEd25519Identity; } } - internal DelegationChainModel Delegation { - get { return mDelegation; } - set + internal DelegationIdentity DelegationIdentity + { + get { return mDelegationIdentity; } + set { - mDelegation = value; - - if (mDelegation != null && mGreetButton != null) + mDelegationIdentity = value; + + if (mDelegationIdentity != null && mGreetButton != null) { mGreetButton.interactable = true; } @@ -45,7 +41,7 @@ void Start() var buttonGo = GameObject.Find("Button_Greet"); mGreetButton = buttonGo?.GetComponent
+
+ +
+
diff --git a/native-apps/unity_ii_deeplink/ii_integration_dapp/src/greet_frontend/src/index.js b/native-apps/unity_ii_deeplink/ii_integration_dapp/src/greet_frontend/src/index.js index 48c5c211e..ea63a5a7e 100644 --- a/native-apps/unity_ii_deeplink/ii_integration_dapp/src/greet_frontend/src/index.js +++ b/native-apps/unity_ii_deeplink/ii_integration_dapp/src/greet_frontend/src/index.js @@ -1,47 +1,30 @@ -import {AuthClient} from "@dfinity/auth-client" -import {SignIdentity} from "@dfinity/agent"; -import {DelegationIdentity, Ed25519PublicKey } from "@dfinity/identity"; - -// An incomplete Ed25519KeyIdentity with only the public key provided. -class IncompleteEd25519KeyIdentity extends SignIdentity { - constructor(publicKey) { - super(); - this._publicKey = publicKey; - } - - getPublicKey () { - return this._publicKey; - } -} - -function fromHexString(hexString) { - return new Uint8Array((hexString.match(/.{1,2}/g) ?? []).map(byte => parseInt(byte, 16))).buffer; -} +import {createActor, greet_backend} from "../../declarations/greet_backend"; +import {AuthClient} from "@dfinity/auth-client"; +import {HttpAgent} from "@dfinity/agent"; +import {DelegationIdentity, Ed25519PublicKey, ECDSAKeyIdentity, DelegationChain} from "@dfinity/identity"; +import {fromHexString} from "@dfinity/identity/lib/cjs/buffer"; -let myKeyIdentity; -let sessionKeyIndex = -1; +let appPublicKey; var url = window.location.href; -sessionKeyIndex = url.indexOf("sessionkey="); -if (sessionKeyIndex !== -1) { - // Parse the public session key and instantiate an IncompleteEd25519KeyIdentity. - var sessionkey = url.substring(sessionKeyIndex + "sessionkey=".length); - - var publicKey = Ed25519PublicKey.fromDer(fromHexString(sessionkey)); - myKeyIdentity = new IncompleteEd25519KeyIdentity(publicKey); -} else { - // TODO: initialize an Ed25519KeyIdentity(); +var publicKeyIndex = url.indexOf("sessionkey="); +if (publicKeyIndex !== -1) { + // Parse the public key. + var publicKeyString = url.substring(publicKeyIndex + "sessionkey=".length); + appPublicKey = Ed25519PublicKey.fromDer(fromHexString(publicKeyString)); } -let delegationIdentity; +let actor = greet_backend; +let delegationChain; const loginButton = document.getElementById("login"); loginButton.onclick = async (e) => { e.preventDefault(); // Create an auth client. + var middleKeyIdentity = await ECDSAKeyIdentity.generate(); let authClient = await AuthClient.create({ - identity: myKeyIdentity, + identity: middleKeyIdentity, }); // Start the login process and wait for it to finish. @@ -53,9 +36,24 @@ loginButton.onclick = async (e) => { }); // At this point we're authenticated, and we can get the identity from the auth client. - const identity = authClient.getIdentity(); - if (identity instanceof DelegationIdentity) { - delegationIdentity = identity; + const middleIdentity = authClient.getIdentity(); + + // Using the identity obtained from the auth client to create an agent to interact with the IC. + const agent = new HttpAgent({identity: middleIdentity}); + actor = createActor(process.env.GREET_BACKEND_CANISTER_ID, { + agent, + }); + + // Create another delegation with the app public key, then we have two delegations on the chain. + if (appPublicKey != null && middleIdentity instanceof DelegationIdentity ) { + let middleToApp = await DelegationChain.create( + middleKeyIdentity, + appPublicKey, + new Date(Date.now() + 15 * 60 * 1000), + { previous: middleIdentity.getDelegation() }, + ); + + delegationChain = middleToApp; } return false; @@ -65,19 +63,33 @@ const openButton = document.getElementById("open"); openButton.onclick = async (e) => { e.preventDefault(); - if (sessionKeyIndex === -1) { - // TODO: warning for not login from a game. + if (delegationChain == null){ + console.log("Invalid delegation chain."); return false; } - + var url = "internetidentity://authorize?"; - if (delegationIdentity != null) { - var delegationString = JSON.stringify(delegationIdentity.getDelegation().toJSON()); - console.log(delegationString); - url = url + "delegation=" + encodeURIComponent(delegationString); - } + var delegationString = JSON.stringify(delegationChain.toJSON()); + url = url + "delegation=" + encodeURIComponent(delegationString); + //console.log(url); window.open(url, "_self"); return false; }; + +const greetButton = document.getElementById("greet"); +greetButton.onclick = async (e) => { + e.preventDefault(); + + greetButton.setAttribute("disabled", true); + + // Interact with backend actor, calling the greet method + const greeting = await actor.greet(); + + greetButton.removeAttribute("disabled"); + + document.getElementById("greeting").innerText = greeting; + + return false; +}; diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll new file mode 100644 index 000000000..6ddfa6c5a Binary files /dev/null and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta new file mode 100644 index 000000000..13f6d5ca5 --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/BouncyCastle.Cryptography.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 593489fde6eec1d409339f2068027223 +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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll deleted file mode 100644 index 99a22be95..000000000 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Chaos.NaCl.dll and /dev/null differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll deleted file mode 100644 index 0181013b5..000000000 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll and /dev/null differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta deleted file mode 100644 index 4c337afdf..000000000 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Dahomey.Cbor.dll.meta +++ /dev/null @@ -1,33 +0,0 @@ -fileFormatVersion: 2 -guid: 2762ae604c55d504b973b2b9a472f2a4 -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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll deleted file mode 100644 index af1d6a3d0..000000000 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll and /dev/null differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta deleted file mode 100644 index e1dba25b7..000000000 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.Cryptography.BLS.dll.meta +++ /dev/null @@ -1,33 +0,0 @@ -fileFormatVersion: 2 -guid: 5ee3fda08d13e3d498234a64d78a5fb4 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - 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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll index 3a93d8125..9d1a43d52 100644 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Agent.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll new file mode 100644 index 000000000..b8f114d09 Binary files /dev/null and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta new file mode 100644 index 000000000..c7e3eca2e --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.BLS.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 933c2d47759680543a7661c61b41b2ae +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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll index 4f3f4e039..6b7348be6 100644 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/EdjCase.ICP.Candid.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md new file mode 100644 index 000000000..b13d4ca7b --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md @@ -0,0 +1,6 @@ +# ICP.NET + +The libraries in ICP.NET are built from https://github.com/BoomDAO/ICP.NET, with + +1. Version `4.0.0`, hashtag `7b51d78b4f4356d767bb86074918a41973c41214`. +2. `ByteUtil` class is changed from `internal` to `public` in `\ICP.NET\src\Candid\Utilities\ByteUtil.cs` file. diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md.meta new file mode 100644 index 000000000..b31a6325d --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4f04216d2bad9a94cb9378defe463e06 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll deleted file mode 100644 index 98774b92a..000000000 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll and /dev/null differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta deleted file mode 100644 index 34b4429c9..000000000 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Collections.Immutable.dll.meta +++ /dev/null @@ -1,27 +0,0 @@ -fileFormatVersion: 2 -guid: 07c068288c2d9674baf2713ade0ce777 -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 - userData: - assetBundleName: - assetBundleVariant: diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll new file mode 100644 index 000000000..f2e77b766 Binary files /dev/null and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta new file mode 100644 index 000000000..d633142ea --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.Formats.Cbor.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: b7149630e9d423f43bbeaf40e8c86807 +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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll deleted file mode 100644 index 5a41247f7..000000000 Binary files a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll and /dev/null differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta deleted file mode 100644 index bc19e5959..000000000 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/System.IO.Pipelines.dll.meta +++ /dev/null @@ -1,33 +0,0 @@ -fileFormatVersion: 2 -guid: ce5b0ae0fccda8548aaf3ae7c72c5758 -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/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll new file mode 100644 index 000000000..b8190e265 Binary files /dev/null and b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll differ diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta new file mode 100644 index 000000000..7d89f570c --- /dev/null +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/ICP.NET/Wasmtime.Dotnet.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 471526ac3bbfe74498c79e74a8c37986 +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/native-apps/unity_ii_deeplink/unity_project/Assets/Scenes/SampleScene.unity b/native-apps/unity_ii_deeplink/unity_project/Assets/Scenes/SampleScene.unity index 62a199e0d..458eb4428 100644 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/Scenes/SampleScene.unity +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/Scenes/SampleScene.unity @@ -168,7 +168,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5c68e31d1a87467468d62c1cd739b0a0, type: 3} m_Name: m_EditorClassIdentifier: - greetBackendCanister: 72rj2-biaaa-aaaan-qdatq-cai + greetFrontend: https://qsgof-4qaaa-aaaan-qekqq-cai.icp0.io/ + greetBackendCanister: qvhir-riaaa-aaaan-qekqa-cai --- !u!114 &272906662 MonoBehaviour: m_ObjectHideFlags: 0 @@ -181,7 +182,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 17feafab2ee1b6b4684003f4b0edc397, type: 3} m_Name: m_EditorClassIdentifier: - greetFrontend: https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io/ --- !u!1 &671559154 GameObject: m_ObjectHideFlags: 0 diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/DeepLinkPlugin.cs b/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/DeepLinkPlugin.cs index 7e297d3d2..8b5b92cae 100644 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/DeepLinkPlugin.cs +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/DeepLinkPlugin.cs @@ -1,7 +1,13 @@ using UnityEngine; +using EdjCase.ICP.Agent; +using EdjCase.ICP.Agent.Identities; +using EdjCase.ICP.Agent.Models; +using EdjCase.ICP.Candid.Models; using EdjCase.ICP.Candid.Utilities; using Newtonsoft.Json; +using System; using System.Web; +using System.Collections.Generic; namespace IC.GameKit { @@ -22,7 +28,7 @@ public void Start() public void OpenBrowser() { - var target = mTestICPAgent.greetFrontend + "?sessionkey=" + ByteUtil.ToHexString(mTestICPAgent.TestIdentity.PublicKey.Value); + var target = mTestICPAgent.greetFrontend + "?sessionkey=" + ByteUtil.ToHexString(mTestICPAgent.TestIdentity.PublicKey.ToDerEncoding()); Application.OpenURL(target); } @@ -40,8 +46,36 @@ public void OnDeepLinkActivated(string url) } var delegationString = HttpUtility.UrlDecode(url.Substring(indexOfDelegation + kDelegationParam.Length)); - var delegation = JsonConvert.DeserializeObject(delegationString); - mTestICPAgent.Delegation = delegation; + mTestICPAgent.DelegationIdentity = ConvertJsonToDelegationIdentity(delegationString); + } + + internal DelegationIdentity ConvertJsonToDelegationIdentity(string jsonDelegation) + { + var delegationChainModel = JsonConvert.DeserializeObject(jsonDelegation); + if (delegationChainModel == null && delegationChainModel.delegations.Length == 0) + { + Debug.LogError("Invalid delegation chain."); + return null; + } + + // Initialize DelegationIdentity. + var delegations = new List(); + foreach (var signedDelegationModel in delegationChainModel.delegations) + { + var pubKey = SubjectPublicKeyInfo.FromDerEncoding(ByteUtil.FromHexString(signedDelegationModel.delegation.pubkey)); + var expiration = ICTimestamp.FromNanoSeconds(Convert.ToUInt64(signedDelegationModel.delegation.expiration, 16)); + var delegation = new Delegation(pubKey, expiration); + + var signature = ByteUtil.FromHexString(signedDelegationModel.signature); + var signedDelegation = new SignedDelegation(delegation, signature); + delegations.Add(signedDelegation); + } + + var chainPublicKey = SubjectPublicKeyInfo.FromDerEncoding(ByteUtil.FromHexString(delegationChainModel.publicKey)); + var delegationChain = new DelegationChain(chainPublicKey, delegations); + var delegationIdentity = new DelegationIdentity(mTestICPAgent.TestIdentity, delegationChain); + + return delegationIdentity; } } } diff --git a/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/TestICPAgent.cs b/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/TestICPAgent.cs index 98c60208a..dfe51e0ad 100644 --- a/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/TestICPAgent.cs +++ b/native-apps/unity_ii_deeplink/unity_project/Assets/Scripts/TestICPAgent.cs @@ -1,35 +1,31 @@ using UnityEngine; using UnityEngine.UI; -using EdjCase.ICP.Agent; using EdjCase.ICP.Agent.Agents; using EdjCase.ICP.Agent.Identities; using EdjCase.ICP.Candid.Models; -using EdjCase.ICP.Candid.Utilities; -using System.Collections.Generic; -using EdjCase.ICP.Agent.Models; -using System; namespace IC.GameKit { public class TestICPAgent : MonoBehaviour { - public string greetFrontend = "https://6x7nu-oaaaa-aaaan-qdaua-cai.icp0.io/"; - public string greetBackendCanister = "72rj2-biaaa-aaaan-qdatq-cai"; + public string greetFrontend = "https://qsgof-4qaaa-aaaan-qekqq-cai.icp0.io/"; + public string greetBackendCanister = "qvhir-riaaa-aaaan-qekqa-cai"; Text mMyPrincipalText = null; Button mGreetButton = null; Ed25519Identity mEd25519Identity = null; - DelegationChainModel mDelegation = null; + DelegationIdentity mDelegationIdentity = null; public Ed25519Identity TestIdentity { get { return mEd25519Identity; } } - internal DelegationChainModel Delegation { - get { return mDelegation; } + internal DelegationIdentity DelegationIdentity + { + get { return mDelegationIdentity; } set { - mDelegation = value; + mDelegationIdentity = value; - if (mDelegation != null && mGreetButton != null) + if (mDelegationIdentity != null && mGreetButton != null) { mGreetButton.interactable = true; } @@ -45,7 +41,7 @@ void Start() var buttonGo = GameObject.Find("Button_Greet"); mGreetButton = buttonGo?.GetComponent