Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
27 changes: 26 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"fast-base64-decode": "^1.0.0"
},
"peerDependencies": {
"react-native": ">=0.81"
"react-native": ">=0.81",
"react-native-windows": "*"
},
"peerDependenciesMeta": {
"react-native-windows": {
"optional": true
}
},
"keywords": [
"Crypto.getRandomValues",
Expand All @@ -23,6 +29,25 @@
"jsSrcsDir": "spec",
"android": {
"javaPackageName": "org.linusu"
},
"windows": {
"namespace": "ReactNativeGetRandomValuesCodegen",
"outputDirectory": "windows/ReactNativeGetRandomValues/codegen",
"separateDataTypes": true
}
},
"devDependencies": {
"@react-native-community/cli": "^20.2.0",
"@types/react": "^19.2.17",
"react": "^19.2.7",
"react-native": "^0.84.1",
"react-native-windows": "^0.84.0"
},
"react-native-windows": {
"init-windows": {
"name": "ReactNativeGetRandomValues",
"namespace": "ReactNativeGetRandomValues",
"template": "cpp-lib"
}
}
}
46 changes: 46 additions & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*AppPackages*
*BundleArtifacts*

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
.vs/
# Visual C++ cache files

#Files generated by the VS build
**/Generated Files/**

#Files generated by MS build
*.binlog
*.err
*.wrn
33 changes: 33 additions & 0 deletions windows/ExperimentalFeatures.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
<!--
Required for building a New Architecture project.

Library projects can change this value to test against Old and New
Architectures when building the library project's local sln file.

Otherwise this value will be decided by the consuming RNW app.

See https://microsoft.github.io/react-native-windows/docs/new-architecture
-->
<RnwNewArch>true</RnwNewArch>

<!--
Changes compilation to assume use of Microsoft.ReactNative NuGet packages
instead of building the framework from source. Defaults to true.

This is set during library project creation and is used when building
the library project's local sln file.

Otherwise this value will be decided by the consuming RNW app.

See https://microsoft.github.io/react-native-windows/docs/nuget
-->
<UseExperimentalNuget>true</UseExperimentalNuget>

<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
</PropertyGroup>

</Project>
43 changes: 43 additions & 0 deletions windows/ReactNativeGetRandomValues.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactNativeGetRandomValues", "ReactNativeGetRandomValues\ReactNativeGetRandomValues.vcxproj", "{F29EA512-C048-4465-8218-4E1283341B65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Debug|ARM64 = Debug|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
Release|ARM64 = Release|ARM64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x64.ActiveCfg = Debug|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x64.Build.0 = Debug|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x64.Deploy.0 = Debug|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x86.ActiveCfg = Debug|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x86.Build.0 = Debug|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|x86.Deploy.0 = Debug|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|ARM64.ActiveCfg = Debug|ARM64
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|ARM64.Build.0 = Debug|ARM64
{F29EA512-C048-4465-8218-4E1283341B65}.Debug|ARM64.Deploy.0 = Debug|ARM64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x64.ActiveCfg = Release|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x64.Build.0 = Release|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x64.Deploy.0 = Release|x64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x86.ActiveCfg = Release|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x86.Build.0 = Release|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Release|x86.Deploy.0 = Release|Win32
{F29EA512-C048-4465-8218-4E1283341B65}.Release|ARM64.ActiveCfg = Release|ARM64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|ARM64.Build.0 = Release|ARM64
{F29EA512-C048-4465-8218-4E1283341B65}.Release|ARM64.Deploy.0 = Release|ARM64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D43FAD39-F619-437D-BB40-04A3982ACB6A}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions windows/ReactNativeGetRandomValues/ReactNativeGetRandomValues.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "pch.h"

#include "ReactNativeGetRandomValues.h"

#include <winrt/Windows.Security.Cryptography.h>

namespace winrt::ReactNativeGetRandomValues
{

std::string RNGetRandomValues::getRandomBase64(double byteLength) noexcept {
auto buffer = Windows::Security::Cryptography::CryptographicBuffer::GenerateRandom(
static_cast<uint32_t>(byteLength));

return winrt::to_string(
Windows::Security::Cryptography::CryptographicBuffer::EncodeToBase64String(buffer));
}

} // namespace winrt::ReactNativeGetRandomValues
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EXPORTS
DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
22 changes: 22 additions & 0 deletions windows/ReactNativeGetRandomValues/ReactNativeGetRandomValues.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "pch.h"
#include "resource.h"

#include "codegen/NativeRNGetRandomValuesSpec.g.h"

#include "NativeModules.h"

namespace winrt::ReactNativeGetRandomValues
{

REACT_MODULE(RNGetRandomValues)
struct RNGetRandomValues
{
using ModuleSpec = ReactNativeGetRandomValuesCodegen::RNGetRandomValuesSpec;

REACT_SYNC_METHOD(getRandomBase64)
std::string getRandomBase64(double byteLength) noexcept;
};

} // namespace winrt::ReactNativeGetRandomValues
Binary file not shown.
143 changes: 143 additions & 0 deletions windows/ReactNativeGetRandomValues/ReactNativeGetRandomValues.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This project was created with react-native-windows 0.84.0 -->
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)\ExperimentalFeatures.props" Condition="Exists('$(SolutionDir)\ExperimentalFeatures.props')" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<MinimalCoreWin>true</MinimalCoreWin>
<ProjectGuid>{F29EA512-C048-4465-8218-4E1283341B65}</ProjectGuid>
<ProjectName>ReactNativeGetRandomValues</ProjectName>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ReactNativeGetRandomValues</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
<AppxPackage>false</AppxPackage>
</PropertyGroup>
<PropertyGroup Label="ReactNativeWindowsProps">
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
<RunAutolinkCheck>false</RunAutolinkCheck>
</PropertyGroup>
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.WindowsSdk.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v145</PlatformToolset>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="ReactNativeWindowsPropertySheets">
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" />
</ImportGroup>
<ItemDefinitionGroup>
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalIncludeDirectories>
$(MSBuildThisFileDirectory);
%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>shell32.lib;user32.lib;windowsapp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
<ModuleDefinitionFile>ReactNativeGetRandomValues.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ClInclude Include="ReactNativeGetRandomValues.h" />
<ClInclude Include="ReactPackageProvider.h">
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
</ClInclude>
<ClInclude Include="resource.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ReactNativeGetRandomValues.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ReactPackageProvider.cpp">
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
</ItemGroup>
<ItemGroup>
<Midl Include="ReactPackageProvider.idl" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ReactNativeGetRandomValues.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ReactNativeWindowsTargets">
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" />
</ImportGroup>
<ItemGroup>
</ItemGroup>
<Target Name="EnsureReactNativeWindowsTargets" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references targets in your node_modules\react-native-windows folder. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props'))" />
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets'))" />
</Target>
</Project>
Loading