![]() |
VOOZH | about |
dotnet add package OpaDotNet.Wasm --version 3.1.0
NuGet\Install-Package OpaDotNet.Wasm -Version 3.1.0
<PackageReference Include="OpaDotNet.Wasm" Version="3.1.0" />
<PackageVersion Include="OpaDotNet.Wasm" Version="3.1.0" />Directory.Packages.props
<PackageReference Include="OpaDotNet.Wasm" />Project file
paket add OpaDotNet.Wasm --version 3.1.0
#r "nuget: OpaDotNet.Wasm, 3.1.0"
#:package OpaDotNet.Wasm@3.1.0
#addin nuget:?package=OpaDotNet.Wasm&version=3.1.0Install as a Cake Addin
#tool nuget:?package=OpaDotNet.Wasm&version=3.1.0Install as a Cake Tool
This is SDK for using WebAssembly (wasm) compiled Open Policy Agent policies with dotnet core.
Initial implementation was based on Open Policy Agent WebAssemby NPM Module
For more information check out the guide.
dotnet add package OpaDotNet.Wasm
To evaluate OPA policy you need to:
using using OpaDotNet.Wasm;
const string data = "{ \"world\": \"world\" }";
using var engine = OpaEvaluatorFactory.CreateFromWasm(
File.OpenRead("policy.wasm")
);
engine.SetDataFromRawJson(data);
IOpaEvaluator has several APIs for policy evaluation:
EvaluatePredicate - Evaluates named policy with specified input. Response interpreted as simple true/false
result.Evaluate - Evaluates named policy with specified input.EvaluateRaw - Evaluates named policy with specified raw JSON input.var policyResult = engine.EvaluatePredicate(inp);
if (policyResult.Result)
{
// We've been authorized.
}
else
{
// Can't do that.
}
See writing policy
You have several options to compile rego policy into wasm module:
package example
default hello = false
hello if {
x := input.message
x == data.world
}
Either use the Compile REST API or opa build CLI tool.
For example, with OPA v0.20.5+:
opa build -t wasm -e example/hello example.rego
Which is compiling the example.rego policy file.
The result will be an OPA bundle with the policy.wasm binary included. See for a more
comprehensive example.
See opa build --help for more details.
You can use SDK to do compilation for you. For more information see OpaDotNet.Compilation.
dotnet add package OpaDotNet.Compilation.Cli
using OpaDotNet.Wasm;
using OpaDotNet.Compilation.Cli;
var compiler = new RegoCliCompiler();
var policyStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy.
using var engine = OpaEvaluatorFactory.CreateFromBundle(policyStream);
dotnet add package OpaDotNet.Compilation.Interop
using OpaDotNet.Wasm;
using OpaDotNet.Compilation.Interop;
var compiler = new RegoInteropCompiler();
var policyStream = await compiler.CompileFile("example.rego", new[] { "example/hello" });
// Use compiled policy.
using var engine = OpaEvaluatorFactory.CreateFromBundle(policyStream);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on OpaDotNet.Wasm:
| Package | Downloads |
|---|---|
|
OpaDotNet.Extensions.AspNetCore
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.0 | 80,561 | 12/15/2025 |
| 3.0.1 | 7,253 | 3/11/2025 |
| 3.0.0-preview-0040 | 347 | 3/5/2025 |
| 3.0.0-preview-0027 | 176 | 2/26/2025 |
| 3.0.0-preview-0004 | 233 | 11/10/2024 |
| 3.0.0-preview-0001 | 228 | 10/25/2024 |
| 3.0.0-preview-0000 | 211 | 10/25/2024 |
| 2.5.1 | 1,674 | 11/8/2024 |
| 2.5.0 | 1,441 | 2/12/2024 |
| 2.4.1 | 475 | 1/26/2024 |
| 2.4.1-pre0004 | 201 | 1/23/2024 |
| 2.4.0 | 537 | 1/10/2024 |
| 2.3.0 | 540 | 11/21/2023 |
| 2.2.0 | 494 | 10/11/2023 |
| 2.2.0-preview0010 | 307 | 10/9/2023 |
| 2.2.0-preview0008 | 283 | 10/3/2023 |
| 2.1.1 | 454 | 9/29/2023 |
| 2.1.0 | 482 | 9/28/2023 |
| 2.0.0 | 645 | 8/18/2023 |
| 2.0.0-preview0012 | 269 | 8/18/2023 |