Quantcast
Jump to content


Optimize Address Fetching in the Samsung Blockchain Keystore SDK with Seed Hash


Recommended Posts

2020-01-20-01-banner.png

Last June, Samsung introduced Samsung Blockchain Keystore (SBK), a secure built-in cold wallet in Galaxy devices. The cold wallet is isolated with Samsung Knox and encapsulated within a defense-grade Trusted Execution Environment (TEE). The Samsung Blockchain Keystore SDK enables use of this wallet in Android applications.

In this article, we discuss how to optimize the address fetching process with seed hash. Fetching addresses from the Samsung Blockchain Keystore using the SDK is time-consuming, so this blog will help you learn how to store your seed hash values to avoid delays in fetching information whenever you launch your app.

The Samsung Blockchain Keystore (SBK) SDK enables users to get blockchain public addresses from the Samsung Blockchain Keystore and sign a cryptocurrency transaction to authenticate. A public address is the hashed version of the public key and is used to recognize a blockchain cryptocurrency account. As the blockchain protocol goes, anyone can fetch the balance and transaction history of an account with its public address.

Developers can invoke the getAddressList() API of the SBK SDK to fetch the address list. Every time this API is called with the same request, you get the same address list. A change to the list occurs only when the wallet's root seed has been changed. The Programming Guide: API Flow and Use Cases provides more detailed information.

Seed hash

The SDK uses the term Seed Hash (see Figure 1, inside the green rectangle).

Figure 1 Figure 1: SBK SDK API flow and use case

The SDK Glossary says:

Seed Hash: A pseudo seed hash that is generated randomly when the HD wallet is created. If the master seed of a wallet is changed, the seed hash will be changed as well.

The getSeedHash() API gets the current seed hash from the Samsung Blockchain Keystore. Fetching the address list from the Samsung Blockchain Keystore using the SBK SDK initiates an expensive operation that requires a considerable amount of time. To provide the user with a seamless experience, the SBK SDK programming guide recommends that developers store information from the getSeedHash() API. Developers then need to invoke the getAddressList() API only when the stored seed hash is different from the seed hash fetched using the SBK SDK.

Prerequisites

Before you begin, be sure you've met these prerequisites:

Store the seed hash

I recommend using Android SharedPreferences to store the seed hash. Remember, the seed hash value is not sensitive data; it's not the wallet's root seed itself. It's a hash value generated to keep track of change in the wallet. Because high-level security is not a concern, and when you have a relatively small collection of key values that you'd like to save, SharedPreferences is an easily implemented solution.

All you need to do is get the SharedPreferences file and then read and write key-value pairs on it. If you prefer another method of storing data, you can select any one of the methods described in the Android: Data and file storage overview.

The following code snippet refers to SharedPreferences:

private static final String seedHashKey = "seed\_hash";
private static final String defaultSeedHashValue = "";
private static SharedPreferences mSharedPreference;

mSharedPreference = getActivity().getPreferences(Context.MODE\_PRIVATE);

public static String getSeedHash() {
    return mSharedPreferences.getString(
                                 seedHashKey, defaultSeedHashValue);
}
public static void setSeedHash(String seedHash) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(seedHashKey, seedHash);
        editor.commit();
    }
}

//Fetch SeedHash from SBK and Store on Share Preference
String seedHashSDK = ScwService.getInstance().getSeedHash();
setSeedHash(seedHashSDK);

Get the address list from the Samsung Blockchain Keystore

The getAddressList() API of the SBK SDK requires the HD path list and callback function parameters.

  • HD path list parameter: An ArrayList, a list of strings in which every string denotes an HD path. See Understanding Keystore > Key Management for more information.
  • Callback function parameter: A callback function of type ScwService.ScwGetAddressListCallback. The address fetching method is performed asynchronously, once the completed onSuccess() or onFailure() method is invoked. onSuccess() holds the required address list as a List, whereas onFailure() holds the error code.

The following code snippet retrieves four addresses at one time:

private ScwService.ScwGetAddressListCallback mScwGetAddressListCallback =
new ScwService.ScwGetAddressListCallback() {
    @Override
    public void onSuccess(List<String> addressList) {
        Log.i(Util.LOG\_TAG,
                       "Accounts fetched from SDK Successfully.");
    }
    @Override
    public void onFailure(int errorCode) {
     // Error Codes Doc:
     // https://img-developer.samsung.com/onlinedocs/blockchain/keystore/
        Log.e(Util.LOG\_TAG,
              "Fetch Accounts Failure. Error Code: " + errorCode);
    }
};

public void getPublicAddress(ArrayList<String> hdPathList) {
    mScwService.getAddressList(
              mScwGetAddressListCallback, hdPathList);
}
ArrayList hdPathList = new ArrayList<>();
hdPathList.add(ScwService.getHdPath(ScwCoinType.ETH, 0));       //m/44'/60'/0'/0/0
hdPathList.add(ScwService.getHdPath(ScwCoinType.ETH, 1));       //m/44'/60'/0'/0/1
hdPathList.add(ScwService.getHdPath(ScwCoinType.ETH, 2));       //m/44'/60'/0'/0/2
hdPathList.add(ScwService.getHdPath(ScwCoinType.ETH, 3));       //m/44'/60'/0'/0/3

//  BTC -> "m/44'/0'/0'/0/0";

getPublicAddress(hdPathList);

Representation

For an Accounts info demonstration, I've used Android's RecyclerView. For detailed information, see Create a List with RecyclerView and this android recyclerview example.

Figure 1 Figure 1 Figure 2: Fetching an address list from the Samsung Blockchain Keystore

Store address information on an application database

Once you have fetched the required addresses from the Samsung Blockchain Keystore, design your mechanism to store this information. Let’s look at requirements at this stage:

  • Storage for account information: Accounts presented at app launch have to remain consistent on subsequent app launches, unless the wallet has been changed.
  • Provide users with a seamless experience: Information should not be fetched from Samsung Blockchain Keystore using SDK every time the app launches, because it causes delays.

This leads us to Android Room. Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

The three major Room components are:

  • Database: Contains the database holder
  • Entity: Represents a table within the database.
  • DAO interface: Contains the methods used for accessing the database.

For more information about Android Room, see the documentation, blogs, and samples.

Database

Database class extends the RoomDatabase and builds the required database file.

@Database(entities = {AccountModel.class}, version = 1)
public abstract class AccountsDB extends RoomDatabase {

    private static AccountsDB accountsDB;
    public abstract IAccountsDAO iAccountsDAO();

    public static AccountsDB getInstance(Context context) {
        if (accountsDB == null || !accountsDB.isOpen()) {
            accountsDB = Room.databaseBuilder
                       (context, AccountsDB.class, Util.DB\_NAME)
                                                         .build();
        }
        return accountsDB;
    }
}

Entity

Here, we have declared our Model Class as a Room Entity using annotations. Room converts “the members of the class” to “columns of the table,” reducing boilerplate code.

@Entity
public class AccountModel {
    // accountID used as primary key & indexing, Auto Generated
    @PrimaryKey(autoGenerate = true)
    private int accountID;

    private String publicAddress;
    private String hdPath;
    // Getter & Setter Methods     
      .. ..
}

DAO interface

Here, you have to declare methods and corresponding database SQL queries to be run. This interface is implemented by the Room persistence library; corresponding codes are generated automatically to perform required database operations.

@Dao
public interface IAccountsDAO {
    @Query("SELECT \* FROM AccountModel")
    List<AccountModel> fetchAccounts();

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAccounts(ArrayList<AccountModel> accountModels);

    @Query("DELETE FROM AccountModel")
    void removeAccounts();
}

On invoking the Java method, corresponding queries are performed on the database. For example, invoking the removeAccounts() method executes the DELETE FROM AccountModel query.

Database operations

Room doesn’t allow you to issue database queries on the main thread, as it can cause delays. Database CRUD operations must be performed on a separate thread.

I’ve used AsyncTask on this example to perform database operations. AsyncTask allows you to perform background operations and publish results on the UI thread without manipulating threads and/or handlers yourself. AsyncTask gives a high-level wrapper over multithreading, so you don't need expertise in concurrent threads or handlers.

  • doInBackground(Params...): Performs a computation on a background thread.
  • onPostExecute (result): Posts on the UI thread once doInBackground() operation is completed. The result parameter holds the execution result returned by doInBackground().
  • execute(Params...): On invocation, executes the task specified with given parameters.

See the API reference for details.

The following example code snippet shows the database retrieve data task:

private static class fetchAsyncTask extends
                   AsyncTask\> {
   @Override
   protected ArrayList<AccountModel> doInBackground(Void...voids){
       ArrayList<AccountModel> accountModels = new                 
           ArrayList<AccountModel>(accountsDB.iAccountsDAO().fetchAccounts());
        return accountModels;
    }

    @Override
    protected void onPostExecute   
                        (ArrayList<AccountModel> accountModels) {
        Log.i(Util.LOG\_TAG, "DB Fetch Successful");
        AccountRepository.setmAccountModels(accountModels);
    }
}

public static void fetchAccounts() {
    // DB CRUD operations has to be performed in a separate thread
    new fetchAsyncTask().execute();
}
Figure 4 Figure 3: Fetching an address list from database

Next steps

It's a lot of technical info for one blog. However, it will be worth it to have your apps launch quickly and seamlessly once you've optimized address fetching in the Samsung Blockchain Keystore SDK. For more detailed information, see the following references, and don't hesitate to reach out with any queries and feedback.

View the full blog at its source

Link to comment
Share on other sites



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      Samsung Electronics today announced that its Tizen OS will be embedded in Loewe’s latest premium TV, stellar, set to launch on July 15 in Europe. This is a significant milestone for the Tizen Licensing Program, which started in 2022 and is now rapidly growing in Europe and worldwide.
       
      “This new collaboration with Loewe ensures that its latest luxury TV, stellar, will exceed expectations with the high-end experiences it brings to consumers,” said YS Kim, EVP, Head of the Service Business Team, Visual Display Business at Samsung Electronics. “It’s also more momentum for Tizen OS, which has established itself as the software platform of choice for premium TVs. Moving forward, we will continue to push the boundaries of how users interact with their TVs.”
       
      Loewe, renowned for its luxury and high-end TVs, has chosen Tizen OS to enhance the viewing experience of its consumers. In particular, the brand is celebrated for its impeccable design and use of premium and unique materials — including stone and concrete back panels. Building on that foundation, this partnership with Samsung underscores the mutual commitment of both companies to deliver superior user experiences.
       
      Tizen OS, based on the newest 2024 Tizen licensing platform, offers a wealth of content and service options, making it the ideal choice for Loewe’s discerning customer base. With Tizen OS, users have access to a wide variety of features, ensuring an unparalleled entertainment experience. Key features include:
       
      Samsung TV Plus: A vast array of free channels and on-demand content, providing a diverse selection of entertainment options. Gaming Hub: Access to top gaming platforms and services, offering an integrated gaming experience of 1,000+ titles without the need of a console. SmartThings: Seamless connection to smart devices in your home.  
      Outside of licensing partnerships, Tizen OS powers 270 million Samsung Smart TVs and offers an intuitive interface that minimizes the steps required for navigation and customization. Tizen OS users can stream their favorite content and play thousands of games — all on one screen — and every aspect of the TV experience is personalized and secured by Samsung Knox.
      View the full article
    • By Shashank Suryavanshi
      Hi, I've developed the Tizen app using the web and now after building it, the build is created in wgt format.
      I want to install the build directly on Samsung Tv so that I can test the app there once.
      I've already created the certificates and it's also verified by the Tizen team.
      Now, when I tried to connect the SamsungTv with Tizen using the Device Manager I'm getting these following errors
      The remote device is already connected by another one. This remote device is running on a non-standard port or There is no IP address, please check the physical connection What I've done?
      I opened the developer mode of Samsung tv and updated the IP address with my system IP address and in the device manager I added all the details what was required and after clicking on add button then I faced the above errors.
      Can anyone help me like how can we either create the build in .tmg format because Usb demo packaging tool is not supported now.  Or how can I connect the SamsungTv with Tizen Studio using the Device Manager. 
      I've read and went through the documentation from official site still I face this issue.
    • By Samsung Newsroom
      The Samsung Odyssey OLED G8 (model name: G80SD) has been making waves in the tech world since its launch on June 4. Garnering accolades like Editor’s Choice, 5-Star Ratings and Highly Recommended badges from multiple review publications, this monitor is being celebrated for its next-level OLED experience and new AI capabilities.
       
      ▲ Samsung Odyssey OLED G8 (G80SD) has been recognized by many leading outlets as a top-rated gaming monitor
       
      The Odyssey OLED G8 is the 32” flat OLED gaming monitor with 4K UHD (3840 x 2160) resolution and a 16:9 aspect ratio. It boasts innovative features such as OLED Glare Free and Samsung’s proprietary burn-in protection technology. Additionally, the monitor is powered by the NQ8 AI Gen3 processor, the same one used in Samsung’s 2024 8K TV. This processor upscales content to nearly 4K when using native Smart TV apps or Samsung Gaming Hub,1 providing a superior viewing experience.
       
      See what each of the following review outlets said about the monitor (listed below in alphabetical order):
       
      CGMagazine Forbes Home Theater Review Newsweek Trusted Reviews  
       
      Groundbreaking Innovations in Gaming Monitors
      Forbes noted that “Samsung has taken the wraps off two cutting edge new additions to its acclaimed Odyssey range of premium gaming monitors, both equipped with advanced features the likes of which we haven’t seen in the monitor world before.”
       
      “What really sets the S32G80SD apart, though, is a trio of ground-breaking new features for the monitor world,” said Forbes. These features include:
       
      The Pulsating Heat Pipe, the first of its kind in a monitor to help prevent burn-in, “delivered in an ultra-thin screen design…can work on an extremely local level, efficiently only impacting the parts of the screen Samsung’s processor identifies as being potential ‘hot spots’.” The OLED Glare Free screen, which “‘rejects’ both ambient and direct light sources almost defies belief… This helps you appreciate the screen’s OLED-powered contrast better and removes one of the most common gaming distractions.” The S32G80SD-optimized NQ8 AI Gen 3 processor, which demonstrates “increased crossover between the gaming monitor and TV worlds.”  
      ▲ The Odyssey OLED G8 is the first monitor in the world to apply a Pulsating Heat Pipe that helps prevent burn-in


      Versatile Gaming and Entertainment Powerhouse
      In addition to Forbes’ recognition, both Home Theater Review and Trusted Reviews acknowledged the groundbreaking features of the G80SD, awarding it top ratings and prestigious accolades.
       
      Trusted Reviews praised the Odyssey OLED G8 with a 5-star rating and their coveted Highly Recommended badge. They noted that the monitor delivers on its multipurpose promises, providing both immersive video performance and exceptional gaming experiences. “Samsung’s S32G80SD is on a mission to take the brand’s gaming monitor division to a whole new level,” said Trusted Reviews. For those looking for a well-rounded monitor, “There’s no other monitor out there right now that does such a fantastic job of switching between its gaming and video ‘sides’ without either feeling compromised by the other.”
       
      Home Theater Review echoed the praise, awarding Samsung’s OLED G8 their 2024 Editors’ Choice award and giving it an overall 5-star rating. They note that Samsung has “cracked the code” with the Odyssey OLED G8, stating that “whether you’re a casual gamer or a die-hard esports competitor, the G8 has you covered… For gamers, the G8 is an absolute dream.”
       
      The outlet was also impressed by the monitor’s versatility, highlighting that “the integrated Samsung Gaming Hub transforms the display into a full-fledged gaming platform.” In fact, the Odyssey OLED G8 can also be used as a standalone TV through the Smart TV functionality, providing access to all the latest apps and streaming services. Home Theater Review concluded, “The G8 delivers an unparalleled experience… setting a new gold standard for all-in-one monitors.”
       
      ▲ The Odyssey OLED G8’s Core Lighting+ provides a more immersive ambiance to the gaming environment
       

      Superior Performance and Design
      Following the recognition from Home Theater Review and Trusted Reviews, both Newsweek and CGMagazine also selected the G80SD as their Editor’s Choice, further affirming its standout performance and design.
       
      Newsweek added to the praise, stating, “The Samsung 32G80SD is a fast 4K OLED monitor with a good smart TV interface and the ability to act as a smart home hub. The display delivers an incredibly fast refresh rate at full 4K resolution and a super fast response rate to give you as much of an edge as you can.” Newsweek also commended the monitor’s “stealthy” and slim design. They also described it as easy to install, taking less than five minutes to do so without any tools.
       
      Impressed by these features, Newsweek credited the Samsung OLED G8 with their Editors’ Choice Award, emphasizing that the display provides “several upgrades to your PC or even a next gen console.”
       
      CGMagazine awarded the Samsung OLED G8 with their Editor’s Choice accolade, giving the monitor an impressive review score of 9 out of 10. They remarked, “The Samsung Odyssey OLED G80SD struts the most when it is pedaling its breakneck 240hz refresh rate over its stunning 4K display.” They were particularly impressed by the monitor’s imagery, noting, “Where the Samsung Odyssey OLED G80SD separates itself from the rest of the pack is with onboard NQ8 AI Gen3 Processing…it feels like it’s the first time you’re seeing a game again through a fresh lens.”
       
      ▲ Samsung Odyssey OLED G8 (G80SD) has been recognized by many leading outlets as a top-rated gaming monitor
       
       
      1 Gaming Hub is available in select countries, with app availability varying by region. AI upscaling functions only when using the built-in Smart TV apps and Samsung Gaming Hub. (PQ priority mode)
      View the full article
    • By Samsung Newsroom
      “Walking along the beach takes me back to my childhood, looking at reflections on the water and the way the horizon keeps changing”
      — Serge Hamad, photographer
       
      Serge Hamad is a visual storyteller whose multifaceted talents as a journalist, photographer and artist have informed the rich tapestry of his work. Having documented sociopolitical issues in war zones earlier in his career as a journalist, he now captures calm and serene seaside images as a photographer. Hamad’s work, including the highly acclaimed “Relax” series, captures tranquility in his signature style and also supports human rights groups with its impact.
       
      Born in the Mediterranean, Hamad has been profoundly influenced by his lifelong fascination with the sea. His photography, characterized by comforting and reflective qualities, has gained widespread recognition from global audiences. Since joining Samsung Art Store in 2020, his work has gained an even wider following as people have interacted with his art in new ways.
       
      This June, Samsung Art Store added two more of his notable pieces — “Beach #61” in the “Colors of Pride” collection and “Beach #64” in “Hello Summer.”
       
      In an interview with Samsung Newsroom, Hamad shared his creative process and how his background and life experiences shape his art, as well as the profound impact his evocative images have had on viewers.
       
      ▲ Serge Hamad
       
       
      An Artist’s Journey
      Q: Please describe your journey into the world of visual arts. What inspired you to move in that direction?
       
      Earlier in my career, I used photography and videography to document various sociopolitical issues as a war zone journalist. In 2011, I decided to shift my focus to capturing more sincere and lighthearted scenes with my lens.
       
      With the “Relax” series,1 my first body of work in fine art, I wanted to share peaceful and placid images with human rights organizations and support them with the proceeds. The public response well surpassed my expectations, so I decided to continue on this path.
       
      Q: Your “Relax” series is well known. What inspired you to shoot a series on the beach?
       
      I was born on the Mediterranean coast, and the sea has always fascinated me. Walking along the beach takes me back to my childhood. I used to love looking at reflections on the water and the way the horizon kept changing.
       
      My multicultural background, being half North African and half Westerner, has profoundly influenced my artistic vision and the themes I explore in my work. This unique blend of cultures allows me to draw from a rich tapestry of traditions and aesthetics, especially when it comes to colors. It has given me a broader perspective, enabling me to see and interpret the world through diverse lenses.
       
      Q: How do you make your beach photography so engaging?
       
      When it comes to capturing an engaging image, planning and timing are crucial. Planning is more than just checking the weather before a shoot — it’s also about selecting the right filming location. For example, I would go to a beach near a marina if I want a shot of a boat on the horizon. To capture a pelican diving into the sea, I would pick a specific beach and go there an hour before sunset. The rest of the atmosphere depends on human interactions with natural elements.
       
      Q: Why does the beach hold so much significance for you?
       
      Consistency is my top priority when developing a collection. I started the “Relax” series at the beach because it is one of the most relaxing places on the planet for millions of people, including myself. I enjoy working at the beach because it reminds me of both the Sahara Desert and the Mediterranean Sea from my childhood.
       
      “I started the ‘Relax’ series at the beach because it is one of the most relaxing places on the planet for millions of people, including myself.”
       
       
      Collaborating With Samsung Art Store
      Q: How do you choose which pieces to share with Samsung Art Store? What emotions or themes do you wish to share? 
       
      I work with Samsung to select pieces that align with a particular themed curation because that way, I can focus on the message delivered to viewers. I strive to convey tranquility and harmony through my pieces on Samsung Art Store.
       
      Q: Samsung Art Store featured “Beach #61” and “Beach #64” in its June collections. Can you share the meaning behind these pieces?
       
      ▲ “Beach #61” (2023)
       
      “Beach #61” was shot in California. The rainbow-colored lifeguard house symbolizes tolerance.
       
      ▲ “Beach #64” (2023)
       
      “Beach #64” is more of a friendly invitation for the viewer to follow my footsteps on a walk at the beach.
       
      Q: Of all the works you’ve made available on Samsung Art Store, what are your three favorites?
       
      I’d have to choose “Beach #4,” “Beach #37” and “Beach #32.” All three photographs show how humans share nature with seabirds.
       
      ▲ “Beach #4” (2011)
       
      “Beach #4” uses a minimalistic approach to convey serenity with natural lines and colors. Before taking this photo, I wondered who would call a taxi to go surfing. It was only when the car approached that I realized it was a lifeguard vehicle.
       
      ▲ “Beach #37” (2016)
       
      I couldn’t resist capturing this scene of a seagull resting on a dune that looked like a charcoal painting.
       
      ▲ “Beach #32” (2014)
       
      Even if the seagulls in “Beach #32” had left and weren’t in the shot, we would still know that they had shared the dune with humans and enjoyed it together. The footprints of both humans and birds on the same dune symbolize their different influences on nature.
       
      “Embracing culture in our homes is always a great idea, and The Frame does just that.”
       
       
      Embracing the Future
      Q: As an artist, how do you feel about the impact of technology on the art world?
       
      Technology has always impacted my work and influenced my approach to photography. As a photographer, I use various tools every day to express myself — and different situations and subjects calls for different tools. Improving technology means giving artists more powerful capabilities to express themselves, so I embrace both analog and digital tools.
       
      In my opinion, artists in all kinds of disciplines have always benefited from innovations. During my career as a photographer, I have seen the popularization of imaging technology to a level that made it accessible to everyone. I believe this has created new artists and will continue to do so. The main thing to keep in mind, though, is that technology is a tool. The artistic process happens in your own mind.
       
      Q: How do you believe your collaboration with Samsung Art Store and The Frame has changed the way people appreciate art in their homes?
       
      The Frame is a brilliant concept, making art more accessible to a wider audience. Embracing culture in our homes is always a great idea, and The Frame does just that.
       
      Q: Is there anything else you would like to share with our readers?
       
      I’m working on a new series called “A table here, a table there.” I plan to spend a few months traveling along the U.S. West Coast to produce it and hope to share the collection by the end of this year.
       
       
      1 All the “Beach” artwork on Samsung Art Store are part of the “Relax” series.
      View the full article





×
×
  • Create New...