Skip to content

Commit

Permalink
Updating unity assets (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekctek authored Jul 25, 2023
1 parent 5dff809 commit 5dd7ce7
Show file tree
Hide file tree
Showing 5 changed files with 1,235 additions and 10 deletions.
6 changes: 6 additions & 0 deletions UnityAssets/Bls.jslib
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var BLS = {
VerifySignature: function (publicKey, messageHash, signature) {
return blsVerify(publicKey, messageHash, signature);
},
};
mergeInto(LibraryManager.library, BLS);
11 changes: 11 additions & 0 deletions UnityAssets/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The following files should be added to the `Plugins/ICP.NET/` directory in Unity
- UnityHttp.cs - An alternative HttpClient that uses UnityWebRequest (needed for WebGL)
To use, create a `UnityHttpClient` instance and when creating an `HttpAgent` pass it as a parameter instead of the default
- WebGlBlsCrytography.cs - The WebGL version of the bls signature verify library, run in the browswer vs in C#/WASM
To use, create a `WebGlBlsCrytography` instance and when creating an `HttpAgent` pass it as a parameter instead of the default
- Bls.jslib - The bridge between the C# code and JS to allow C# to invoke the JS bls signature verification

Other files:
- bls.js - Add to unity project and reference from an HTML file with a script tag. Loads in the JS bls signature verification that will be used with `WebGlBlsCrytography.cs`.
To generate the bls.js file, run `npx esbuild --bundle src/index.ts --outfile=dist/index.js` on github.com/dfinity/agent-js project in the directory `packages/bls-verify/`
Also modify the bls.js file to change `var blsVerify = ...` to `window.blsVerify = ...`. // TODO find a better way to export function
10 changes: 0 additions & 10 deletions UnityAssets/WebGlBls.cs

This file was deleted.

28 changes: 28 additions & 0 deletions UnityAssets/WebGlBlsCryptography.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Cysharp.Threading.Tasks;
using EdjCase.ICP.Agent.Agents.Http;
using EdjCase.ICP.BLS;
using System;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;

#if UNITY_WEBGL
public class WebGlBlsCryptography : IBlsCryptography
{
public bool VerifySignature(byte[] publicKey, byte[] messageHash, byte[] signature)
{
return BrowserBlsLib.VerifySignature(publicKey, messageHash, signature);
}
}

internal static class BrowserBlsLib
{
[DllImport("__Internal")]
public static extern bool VerifySignature(byte[] publicKey, byte[] messageHash, byte[] signature);
}
#endif

Loading

0 comments on commit 5dd7ce7

Please sign in to comment.