diff --git a/src/index.ts b/src/index.ts index 5b5902ef16..43347506b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,6 +62,7 @@ import {Printer} from './plugins/printer'; import {Push} from './plugins/push'; import {SafariViewController} from './plugins/safari-view-controller'; import {Screenshot} from './plugins/screenshot'; +import {SecureStorage} from './plugins/securestorage'; import {Sim} from './plugins/sim'; import {SMS} from './plugins/sms'; import {SocialSharing} from './plugins/socialsharing'; @@ -139,6 +140,7 @@ export { OneSignal, PinDialog, Screenshot, + SecureStorage, SocialSharing, Sim, Splashscreen, @@ -211,6 +213,7 @@ window['IonicNative'] = { PinDialog: PinDialog, SafariViewController: SafariViewController, Screenshot: Screenshot, + SecureStorage: SecureStorage, Sim: Sim, SMS: SMS, SocialSharing: SocialSharing, diff --git a/src/plugins/securestorage.ts b/src/plugins/securestorage.ts new file mode 100644 index 0000000000..7b3061620b --- /dev/null +++ b/src/plugins/securestorage.ts @@ -0,0 +1,92 @@ +import { CordovaInstance, Plugin } from './plugin'; + +declare var cordova: any; + +/** + * @name Secure Storage + * @description + * This plugin gets, sets and removes key,value pairs from a device's secure storage. + * + * Requires Cordova plugin: `cordova-plugin-secure-storage`. For more info, please see the [Cordova Secure Storage docs](https://github.com/Crypho/cordova-plugin-secure-storage). + * + * @usage + * + * ```typescript + * import { SecureStorage } from 'ionic-native'; + * + * let secureStorage: SecureStorage = new SecureStorage(); + * secureStorage.create('my_store_name') + * .then( + * () => console.log('Success'), + * error => console.log(error); + * ); + * + * secureStorage.get('myitem') + * .then( + * data => console.log(data), + * error => console.log(error) + * ); + * + * secureStorage.set('myitem', 'myvalue') + * .then( + * data => console.log(data), + * error => console.log(error) + * ); + * + * secureStorage.remove('myitem') + * .then( + * data => console.log(data), + * error => console.log(error) + * ); + * ``` + */ +@Plugin({ + plugin: 'cordova-plugin-secure-storage', + pluginRef: 'plugins.securestorage', + repo: 'https://github.com/Crypho/cordova-plugin-secure-storage', + platforms: ['Android', 'iOS', 'Windows Phone', 'Browser'] +}) +export class SecureStorage { + + private _objectInstance: any; + + constructor() {} + + /** + * Creates a namespaced storage. + * @param store {string} + */ + create(store: string): Promise { + return new Promise((res, rej) => { + this._objectInstance = new cordova.plugins.SecureStorage(res, rej, store); + }); + } + + /** + * Gets a stored item + * @param reference {string} + */ + @CordovaInstance({ + callbackOrder: 'reverse' + }) + get(reference: string): Promise { return; } + + /** + * Stores a value + * @param reference {string} + * @param value {string} + */ + @CordovaInstance({ + callbackOrder: 'reverse' + }) + set(reference: string, value: string): Promise { return; } + + /** + * Removes a single stored item + * @param reference {string} + */ + @CordovaInstance({ + callbackOrder: 'reverse' + }) + remove(reference: string): Promise { return; } +}