-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from Etherna/feature/BNET-103-build-wasm
Feature/bnet 103 build wasm
- Loading branch information
Showing
8 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WebAssembly"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<RootNamespace>Etherna.BeeNet.Wasm</RootNamespace> | ||
|
||
<Authors>Etherna SA</Authors> | ||
<Description>Utility services to work with Ethereum Swarm with WASM</Description> | ||
|
||
<IsPackable>false</IsPackable> | ||
<EnableNETAnalyzers>true</EnableNETAnalyzers> | ||
<AnalysisMode>AllEnabledByDefault</AnalysisMode> | ||
|
||
<RepositoryUrl>https://github.com/Etherna/bee-net</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageLicenseFile>COPYING</PackageLicenseFile> | ||
<PackageLicenseFile>COPYING-LESSER</PackageLicenseFile> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\COPYING" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\COPYING-LESSER" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BeeNet.Util\BeeNet.Util.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Etherna.BeeNet.Services; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.InteropServices.JavaScript; | ||
using System.Threading.Tasks; | ||
|
||
#pragma warning disable CA1303 | ||
Console.WriteLine("Main, don't remove!"); | ||
#pragma warning restore CA1303 | ||
|
||
[SuppressMessage("Design", "CA1052:Static holder types should be Static or NotInheritable")] | ||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] | ||
[SuppressMessage("Design", "CA1050:Declare types in namespaces")] | ||
public partial class BeeNetWasmUtil | ||
{ | ||
[JSExport] | ||
internal static async Task<string> GetHashStringAsync( | ||
byte[] data, | ||
string fileContentType, | ||
string fileName) | ||
{ | ||
var calculatorService = new CalculatorService(); | ||
var result = await calculatorService.EvaluateFileUploadAsync( | ||
data, | ||
fileContentType, | ||
fileName).ConfigureAwait(false); | ||
return result.Hash.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
[assembly: System.Runtime.Versioning.SupportedOSPlatform("browser")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"profiles": { | ||
"BeeNet.Util.Wasm": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:7080;http://localhost:5094", | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"wasmHostProperties": { | ||
"perHostConfig": [ | ||
{ | ||
"name": "browser", | ||
"host": "browser" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
<!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
<html> | ||
|
||
<head> | ||
<title>BeeNet.Util.Wasm</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
|
||
<body> | ||
<span id="out"></span> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import { dotnet } from './_framework/dotnet.js' | ||
|
||
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet | ||
.withDiagnosticTracing(false) | ||
.withApplicationArgumentsFromQuery() | ||
.create(); | ||
|
||
setModuleImports('main.js', { | ||
window: { | ||
location: { | ||
href: () => globalThis.window.location.href | ||
} | ||
} | ||
}); | ||
|
||
const config = getConfig(); | ||
const exports = await getAssemblyExports(config.mainAssemblyName); | ||
|
||
let utf8Encode = new TextEncoder(); | ||
let array = utf8Encode.encode("Bzz over the world!"); | ||
|
||
const hash = await exports.BeeNetWasmUtil.GetHashStringAsync( | ||
array, | ||
"text/plain", | ||
"hello.txt" | ||
); | ||
console.log(hash); | ||
|
||
document.getElementById('out').innerHTML = hash; | ||
await dotnet.run(); |