diff --git a/README.md b/README.md index fb90032..81c617e 100644 --- a/README.md +++ b/README.md @@ -105,3 +105,15 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand ... ``` + +### `Windows` + + +```bash +react-native link react-native-randombytes +``` + +Depending on your project versions and the state of RN-Windows this may not always work. If it does not, a manual installation guide can be found here: + +https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c55c8d5 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,38 @@ +{ + "name": "react-native-randombytes", + "version": "3.5.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "base64-js": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", + "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" + }, + "buffer": { + "version": "4.9.1", + "resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", + "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4", + "isarray": "^1.0.0" + } + }, + "ieee754": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz", + "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA==" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "sjcl": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.7.tgz", + "integrity": "sha1-MrNlpQ3Ju6JriLo8nfjqNCF9n0U=" + } + } +} diff --git a/windows/.gitignore b/windows/.gitignore new file mode 100644 index 0000000..cbf7e7f --- /dev/null +++ b/windows/.gitignore @@ -0,0 +1,78 @@ +*AppPackages* +*BundleArtifacts* +*ReactAssets* + +#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 + +#MonoDevelop +*.pidb +*.userprefs + +#Tooling +_ReSharper*/ +*.resharper +[Tt]est[Rr]esult* +*.sass-cache + +#Project files +[Bb]uild/ + +#Subversion files +.svn + +# Office Temp Files +~$* + +# vim Temp Files +*~ + +#NuGet +packages/ +*.nupkg + +#ncrunch +*ncrunch* +*crunch*.local.xml + +# visual studio database projects +*.dbmdl + +#Test files +*.testsettings + +#Other files +*.DotSettings +.vs/ +*project.lock.json diff --git a/windows/.npmignore b/windows/.npmignore new file mode 100644 index 0000000..dd626ca --- /dev/null +++ b/windows/.npmignore @@ -0,0 +1,9 @@ + +# Make sure we don't publish build artifacts to NPM +ARM/ +Debug/ +x64/ +x86/ +bin/ +obj/ +.vs/ diff --git a/windows/RNRandomBytes.sln b/windows/RNRandomBytes.sln new file mode 100644 index 0000000..fdbfbd2 --- /dev/null +++ b/windows/RNRandomBytes.sln @@ -0,0 +1,90 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RNRandomBytes", "RNRandomBytes\RNRandomBytes.csproj", "{5BFF4280-CE24-11E8-928D-098870C3A6C6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNative", "..\node_modules\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj", "{C7673AD5-E3AA-468C-A5FD-FA38154E205C}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ReactNative.Shared", "..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.shproj", "{EEA8B852-4D07-48E1-8294-A21AB5909FE5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChakraBridge", "..\node_modules\react-native-windows\ReactWindows\ChakraBridge\ChakraBridge.vcxproj", "{4B72C796-16D5-4E3A-81C0-3E36F531E578}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4 + ..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{eea8b852-4d07-48e1-8294-a21ab5909fe5}*SharedItemsImports = 13 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Development|ARM = Development|ARM + Development|x64 = Development|x64 + Development|x86 = Development|x86 + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|ARM.ActiveCfg = Debug|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|ARM.Build.0 = Debug|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|x64.ActiveCfg = Debug|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|x64.Build.0 = Debug|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|x86.ActiveCfg = Debug|x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Debug|x86.Build.0 = Debug|x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|ARM.ActiveCfg = Development|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|ARM.Build.0 = Development|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|x64.ActiveCfg = Development|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|x64.Build.0 = Development|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|x86.ActiveCfg = Development|x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Development|x86.Build.0 = Development|x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|ARM.ActiveCfg = Release|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|ARM.Build.0 = Release|ARM + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|x64.ActiveCfg = Release|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|x64.Build.0 = Release|x64 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|x86.ActiveCfg = Release|x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6}.Release|x86.Build.0 = Release|x86 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.ActiveCfg = Debug|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.Build.0 = Debug|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x64.ActiveCfg = Debug|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x64.Build.0 = Debug|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x86.ActiveCfg = Debug|x86 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x86.Build.0 = Debug|x86 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|ARM.ActiveCfg = Debug|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|ARM.Build.0 = Debug|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x64.ActiveCfg = Debug|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x64.Build.0 = Debug|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x86.ActiveCfg = Debug|x86 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x86.Build.0 = Debug|x86 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|ARM.ActiveCfg = Release|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|ARM.Build.0 = Release|ARM + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x64.ActiveCfg = Release|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x64.Build.0 = Release|x64 + {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x86.ActiveCfg = Release|x86 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|ARM.ActiveCfg = Debug|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|ARM.Build.0 = Debug|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x64.ActiveCfg = Debug|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x64.Build.0 = Debug|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x86.ActiveCfg = Debug|Win32 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x86.Build.0 = Debug|Win32 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|ARM.ActiveCfg = Debug|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|ARM.Build.0 = Debug|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x64.ActiveCfg = Debug|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x64.Build.0 = Debug|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x86.ActiveCfg = Debug|Win32 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x86.Build.0 = Debug|Win32 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|ARM.ActiveCfg = Release|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|ARM.Build.0 = Release|ARM + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x64.ActiveCfg = Release|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x64.Build.0 = Release|x64 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x86.ActiveCfg = Release|Win32 + {4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C6039EC8-B41F-408A-82DC-64E56672BA27} + EndGlobalSection +EndGlobal diff --git a/windows/RNRandomBytes/Properties/AssemblyInfo.cs b/windows/RNRandomBytes/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ba559cd --- /dev/null +++ b/windows/RNRandomBytes/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("RNRandomBytes")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RNRandomBytes")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] + \ No newline at end of file diff --git a/windows/RNRandomBytes/Properties/RNRandomBytes.rd.xml b/windows/RNRandomBytes/Properties/RNRandomBytes.rd.xml new file mode 100644 index 0000000..0f47a9e --- /dev/null +++ b/windows/RNRandomBytes/Properties/RNRandomBytes.rd.xml @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/windows/RNRandomBytes/RNRandomBytes.csproj b/windows/RNRandomBytes/RNRandomBytes.csproj new file mode 100644 index 0000000..c759fa5 --- /dev/null +++ b/windows/RNRandomBytes/RNRandomBytes.csproj @@ -0,0 +1,153 @@ + + + + + Debug + x86 + {5BFF4280-CE24-11E8-928D-098870C3A6C6} + Library + Properties + Random.Bytes + Random.Bytes + en-US + UAP + 10.0.17134.0 + 10.0.14393.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\node_modules + + + ..\.. + + + x86 + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x86 + false + prompt + + + x86 + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x86 + false + prompt + + + ARM + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM + false + prompt + + + ARM + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM + false + prompt + + + x64 + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + + + x64 + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + + + true + bin\x86\Development\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + true + full + x86 + false + prompt + MinimumRecommendedRules.ruleset + + + true + bin\ARM\Development\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + true + full + ARM + false + prompt + MinimumRecommendedRules.ruleset + + + true + bin\x64\Development\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + true + full + x64 + false + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + {c7673ad5-e3aa-468c-a5fd-fa38154e205c} + ReactNative + + + + 14.0 + + + + \ No newline at end of file diff --git a/windows/RNRandomBytes/RNRandomBytesModule.cs b/windows/RNRandomBytes/RNRandomBytesModule.cs new file mode 100644 index 0000000..1392e20 --- /dev/null +++ b/windows/RNRandomBytes/RNRandomBytesModule.cs @@ -0,0 +1,59 @@ +using ReactNative.Bridge; +using System; +using System.Collections.Generic; +using Windows.ApplicationModel.Core; +using Windows.UI.Core; +using Windows.Storage.Streams; +using Windows.Security.Cryptography; + +namespace Random.Bytes.RNRandomBytes +{ + /// + /// A module that allows JS to share data. + /// + class RNRandomBytesModule : NativeModuleBase + { + private static string SEED_KEY = "seed"; + /// + /// Instantiates the . + /// + internal RNRandomBytesModule() + { + } + + /// + /// The name of the native module. + /// + public override string Name + { + get + { + return "RNRandomBytes"; + } + } + + public override IReadOnlyDictionary Constants + { + get + { + return new Dictionary + { + {SEED_KEY, getRandomBytes(4096)} + }; + } + } + + [ReactMethod] + public void randomBytes(uint size, IPromise promise) + { + promise.Resolve(this.getRandomBytes(size)); + } + + private string getRandomBytes(uint size) + { + IBuffer buffer = CryptographicBuffer.GenerateRandom(size); + return CryptographicBuffer.EncodeToHexString(buffer); + } + + } +} \ No newline at end of file diff --git a/windows/RNRandomBytes/RNRandomBytesPackage.cs b/windows/RNRandomBytes/RNRandomBytesPackage.cs new file mode 100644 index 0000000..0b526de --- /dev/null +++ b/windows/RNRandomBytes/RNRandomBytesPackage.cs @@ -0,0 +1,53 @@ +using ReactNative.Bridge; +using ReactNative.Modules.Core; +using ReactNative.UIManager; +using System; +using System.Collections.Generic; + +namespace Random.Bytes.RNRandomBytes +{ + /// + /// Package defining core framework modules (e.g., ). + /// It should be used for modules that require special integration with + /// other framework parts (e.g., with the list of packages to load view + /// managers from). + /// + public class RNRandomBytesPackage : IReactPackage + { + /// + /// Creates the list of native modules to register with the react + /// instance. + /// + /// The react application context. + /// The list of native modules. + public IReadOnlyList CreateNativeModules(ReactContext reactContext) + { + return new List + { + new RNRandomBytesModule(), + }; + } + + /// + /// Creates the list of JavaScript modules to register with the + /// react instance. + /// + /// The list of JavaScript modules. + public IReadOnlyList CreateJavaScriptModulesConfig() + { + return new List(0); + } + + /// + /// Creates the list of view managers that should be registered with + /// the . + /// + /// The react application context. + /// The list of view managers. + public IReadOnlyList CreateViewManagers( + ReactContext reactContext) + { + return new List(0); + } + } +} diff --git a/windows/RNRandomBytes/project.json b/windows/RNRandomBytes/project.json new file mode 100644 index 0000000..89d0fa7 --- /dev/null +++ b/windows/RNRandomBytes/project.json @@ -0,0 +1,16 @@ +{ + "dependencies": { + "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2" + }, + "frameworks": { + "uap10.0": {} + }, + "runtimes": { + "win10-arm": {}, + "win10-arm-aot": {}, + "win10-x86": {}, + "win10-x86-aot": {}, + "win10-x64": {}, + "win10-x64-aot": {} + } +}