SecureStorage-0.10.0

    SecureStorage-0.10.0


    Article summary


    title: SecureStorage

    # SecureStorage Module

    Version 0.10.0

    Overview

    A module for storing and retrieving secure data owned by the app

    OpenRPC

    Firebolt APIs are maintained in the rdkcentral/firebolt-core-sdk GitHub repository.

    You can see this API in the securestorage.json OpenRPC JSON-Schema document.

    Table of Contents

    Usage

    To use the SecureStorage module, you can import it into your project from the Firebolt SDK:

    import { SecureStorage } from '@firebolt-js/sdk'
    

    Methods

    get

    Get stored value by key

    function get(scope: StorageScope, key: string): Promise<string | null>
    

    Parameters:

    ParamTypeRequiredSummary
    scopeStorageScopetrueThe scope of the key/value
    keystringtrueKey to get

    Promise resolution:

    TypeDescription
    string \| nullThe retrieved value, if found.

    Examples

    Successfully retrieve a refresh token with key authRefreshToken

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.get("device", "authRefreshToken")
        .then(value => {
            console.log(value)
        })
    

    Value of value:

    "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.get",
      "params": {
        "scope": "device",
        "key": "authRefreshToken"
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    }
    
    More examples...Attempt to retrieve a key with no value set

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.get("account", "authRefreshToken")
        .then(value => {
            console.log(value)
        })
    

    Value of value:

    null
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.get",
      "params": {
        "scope": "account",
        "key": "authRefreshToken"
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": null
    }
    

    set

    Set or update a secure data value

    function set(scope: StorageScope, key: string, value: string, options?: StorageOptions): Promise<void>
    

    Parameters:

    ParamTypeRequiredSummary
    scopeStorageScopetrueThe scope of the data key
    keystringtrueKey to set
    valuestringtrueValue to set
    optionsStorageOptionsfalseOptional parameters to set

    Promise resolution:

    void
    

    Examples

    Set a refresh token with name authRefreshToken with optional paramter

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.set("device", "authRefreshToken", "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=", {"ttl":600})
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.set",
      "params": {
        "scope": "device",
        "key": "authRefreshToken",
        "value": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=",
        "options": {
          "ttl": 600
        }
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": null
    }
    
    More examples...Set a refresh token with name authRefreshToken without optional parameter

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.set("account", "authRefreshToken", "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=", null)
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.set",
      "params": {
        "scope": "account",
        "key": "authRefreshToken",
        "value": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": null
    }
    

    remove

    Remove a secure data value

    function remove(scope: StorageScope, key: string): Promise<void>
    

    Parameters:

    ParamTypeRequiredSummary
    scopeStorageScopetrueThe scope of the data key
    keystringtrueKey to remove

    Promise resolution:

    void
    

    Examples

    Remove the value with key authRefreshToken for device

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.remove("device", "authRefreshToken")
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.remove",
      "params": {
        "scope": "device",
        "key": "authRefreshToken"
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": null
    }
    
    More examples...Remove the value with key authRefreshToken for account

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.remove("account", "authRefreshToken")
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "securestorage.remove",
      "params": {
        "scope": "account",
        "key": "authRefreshToken"
      }
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": null
    }
    

    Schemas

    StorageScope

    The scope of the data

    type StorageScope = 'device' | 'account'
    

    StorageOptions

    type StorageOptions = {
      ttl: number            // Seconds from set time before the data expires and is removed
    }
    


    Was this article helpful?

    What's Next