diff --git a/README.md b/README.md index b082d82..b186d1d 100644 --- a/README.md +++ b/README.md @@ -96,31 +96,12 @@ All methods are asynchronous and return promises (except for convert utils) - verify(data: string, secretToVerify: string, hash: string) - utils - randomBytes(bytes: number) - - convert - - ArrayBuffer - - to - - Utf8(input: ArrayBuffer) - - Hex(input: ArrayBuffer) - - Base64(input: ArrayBuffer) - - from - - Utf8(input: string) - - Hex(input: string) - - Base64(input: string) - - Utf8 - - to - - ArrayBuffer(input: string) - - from - - ArrayBuffer(input: ArrayBuffer) - - Hex - - to - - ArrayBuffer(input: string) - - from - - ArrayBuffer(input: ArrayBuffer) - - Base64 - - to - - ArrayBuffer(input: string) - - from - - ArrayBuffer(input: ArrayBuffer) + - convertArrayBufferToUtf8(input: ArrayBuffer) + - convertUtf8ToArrayBuffer(input: string) + - convertArrayBufferToBase64(input: ArrayBuffer) + - convertBase64ToArrayBuffer(input: string) + - convertArrayBufferToHex(input: ArrayBuffer) + - convertHexToArrayBuffer(input: string) ``` > _NOTE:_ Supported hashing algorithms for RSA and PBKDF2 are: @@ -135,7 +116,7 @@ import RNSimpleCrypto from "react-native-simple-crypto"; // -- AES ------------------------------------------------------------- // const message = "data to encrypt"; -const messageArrayBuffer = RNSimpleCrypto.utils.convert.Utf8.to.ArrayBuffer( +const messageArrayBuffer = RNSimpleCrypto.utils.convertUtf8ToArrayBuffer( message ); @@ -157,7 +138,7 @@ const messageArrayBuffer = await RNSimpleCrypto.AES.decrypt( keyArrayBuffer, ivArrayBuffer ); -const message = RNSimpleCrypto.utils.convert.ArrayBuffer.to.Utf8( +const message = RNSimpleCrypto.utils.convertArrayBufferToUtf8( messageArrayBuffer ); console.log("AES decrypt", message); @@ -166,7 +147,7 @@ console.log("AES decrypt", message); const signatureArrayBuffer = await RNSimpleCrypto.HMAC.hmac256(message, key); -const signatureHex = RNSimpleCrypto.utils.convert.ArrayBuffer.to.Hex( +const signatureHex = RNSimpleCrypto.utils.convertArrayBuffertoHex( signatureArrayBuffer ); console.log("HMAC signature", signatureHex); diff --git a/index.d.ts b/index.d.ts index 2e785ea..502b4f2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,43 +62,11 @@ declare module "react-native-simple-crypto" { export namespace utils { export function randomBytes(bytes: number): Promise; - export interface convert { - ArrayBuffer: { - to: { - Utf8: (arrayBuffer: ArrayBuffer) => string; - Hex: (arrayBuffer: ArrayBuffer) => string; - Base64: (arrayBuffer: ArrayBuffer) => string; - }; - from: { - Utf8: (string: string) => ArrayBuffer; - Hex: (string: string) => ArrayBuffer; - Base64: (string: string) => ArrayBuffer; - }; - }; - Utf8: { - to: { - ArrayBuffer: (string: string) => ArrayBuffer; - }; - from: { - ArrayBuffer: (arrayBuffer: ArrayBuffer) => string; - }; - }; - Hex: { - to: { - ArrayBuffer: (string: string) => ArrayBuffer; - }; - from: { - ArrayBuffer: (arrayBuffer: ArrayBuffer) => string; - }; - }; - Base64: { - to: { - ArrayBuffer: (string: string) => ArrayBuffer; - }; - from: { - ArrayBuffer: (arrayBuffer: ArrayBuffer) => string; - }; - }; - } + export function convertArrayBufferToUtf8(input: ArrayBuffer): string; + export function convertUtf8ToArrayBuffer(input: string): ArrayBuffer; + export function convertArrayBufferToBase64(input: ArrayBuffer): string; + export function convertBase64ToArrayBuffer(input: string): ArrayBuffer; + export function convertArrayBufferToHex(input: ArrayBuffer): string; + export function convertHexToArrayBuffer(input: string): ArrayBuffer; } } diff --git a/index.js b/index.js index c829308..06c5ce5 100644 --- a/index.js +++ b/index.js @@ -159,44 +159,12 @@ const RSA = NativeModules.Rsa; const utils = { randomBytes: randomBytes, - convert: { - ArrayBuffer: { - to: { - Utf8: convertArrayBufferToUtf8, - Hex: convertArrayBufferToHex, - Base64: convertArrayBufferToBase64 - }, - from: { - Utf8: convertUtf8ToArrayBuffer, - Hex: convertHexToArrayBuffer, - Base64: convertBase64ToArrayBuffer - } - }, - Utf8: { - to: { - ArrayBuffer: convertUtf8ToArrayBuffer - }, - from: { - ArrayBuffer: convertArrayBufferToUtf8 - } - }, - Hex: { - to: { - ArrayBuffer: convertHexToArrayBuffer - }, - from: { - ArrayBuffer: convertArrayBufferToHex - } - }, - Base64: { - to: { - ArrayBuffer: convertBase64ToArrayBuffer - }, - from: { - ArrayBuffer: convertArrayBufferToBase64 - } - } - } + convertArrayBufferToUtf8: convertArrayBufferToUtf8, + convertUtf8ToArrayBuffer: convertUtf8ToArrayBuffer, + convertArrayBufferToBase64: convertArrayBufferToBase64, + convertBase64ToArrayBuffer: convertBase64ToArrayBuffer, + convertArrayBufferToHex: convertArrayBufferToHex, + convertHexToArrayBuffer: convertHexToArrayBuffer }; export default {