NYMnemonic.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // NYMnemonic.h
  2. //
  3. // Copyright (c) 2014 Nybex, Inc. (https://nybex.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. #import <Foundation/Foundation.h>
  23. #import <CommonCrypto/CommonHMAC.h>
  24. #import <CommonCrypto/CommonKeyDerivation.h>
  25. /**
  26. `NYMnemonic` is an objective-c implimentation of BIP-39 style mnemonic codes
  27. for use with generating deterministic keys.
  28. */
  29. @interface NYMnemonic : NSObject
  30. /**
  31. Creates a mnemonic code from a hex encoded seed.
  32. @param seed The hex encoded random seed. Should be between 128-256 bits
  33. @param language The language file to use. Currently the only value is 'english'
  34. @return a string containing the mnemonic code
  35. */
  36. + (NSString *)mnemonicStringFromRandomHexString:(NSString *)seed
  37. language:(NSString *)language;
  38. /**
  39. Creates a mnemonic code from a hex encoded seed.
  40. @param mnemonic The mnemonic phrase to use as the deterministic seed
  41. @param passphrase A passphrase to be applied when creating the seed
  42. @param language The language file to use. Currently the only value is 'english'
  43. @return a string containing the deterministic seed
  44. */
  45. + (NSString *)deterministicSeedStringFromMnemonicString:(NSString *)mnemonic
  46. passphrase:(NSString *)passphrase
  47. language:(NSString *)language;
  48. /**
  49. Creates a mnemonic code from a hex encoded seed.
  50. @param strength The strength of code, should be >=128 & <=256 & divisible by 32
  51. @param language The language file to use. Currently the only value is 'english'
  52. @return a string containing the mnemonic code
  53. */
  54. + (NSString *)generateMnemonicString:(NSNumber *)strength
  55. language:(NSString *)language;
  56. @end
  57. /**
  58. Category on NSData that helps with conversion to bit arrays and to hex
  59. strings.
  60. */
  61. @interface NSData (NYMnemonic)
  62. - (NSString *)ny_hexString;
  63. - (NSArray *)ny_hexToBitArray;
  64. @end
  65. /**
  66. Category on NSString to convert a hex string to NSData
  67. @return NSData
  68. */
  69. @interface NSString (NYMnemonic)
  70. - (NSData *)ny_dataFromHexString;
  71. @end