1 | //
|
2 | // RNRandom.m
|
3 | // randombytes
|
4 | //
|
5 | // Created by Mark Vayngrib on 10/13/15.
|
6 | // Copyright (c) 2015 Facebook. All rights reserved.
|
7 | //
|
8 |
|
9 | #import "RNRandomBytes.h"
|
10 | #import "RCTBridgeModule.h"
|
11 | #import "RCTBridge.h"
|
12 |
|
13 | @implementation RNRandomBytes
|
14 |
|
15 | RCT_EXPORT_MODULE()
|
16 |
|
17 | @synthesize bridge = _bridge;
|
18 |
|
19 | RCT_EXPORT_METHOD(randomBytes:(NSUInteger)length
|
20 | callback:(RCTResponseSenderBlock)callback)
|
21 | {
|
22 | callback(@[[NSNull null], [self randomBytes:length]]);
|
23 | }
|
24 |
|
25 | - (NSString *) randomBytes:(NSUInteger)length
|
26 | {
|
27 | NSMutableData* bytes = [NSMutableData dataWithLength:length];
|
28 | SecRandomCopyBytes(kSecRandomDefault, length, [bytes mutableBytes]);
|
29 | return [bytes base64EncodedStringWithOptions:0];
|
30 | }
|
31 |
|
32 | - (NSDictionary *)constantsToExport
|
33 | {
|
34 | return @{
|
35 | @"seed": [self randomBytes:4096]
|
36 | };
|
37 | };
|
38 |
|
39 | @end
|