From 36f16386ef32286e5843ddcfc570df2f2f406a67 Mon Sep 17 00:00:00 2001 From: Russel Date: Mon, 12 Oct 2020 10:31:05 +0300 Subject: [PATCH] add factory method to create storage keys without identifier --- FearlessUtils.podspec | 2 +- FearlessUtils/Classes/Common/StorageKeyFactory.swift | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/FearlessUtils.podspec b/FearlessUtils.podspec index e953ed1..df949e3 100644 --- a/FearlessUtils.podspec +++ b/FearlessUtils.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'FearlessUtils' - s.version = '0.6.0' + s.version = '0.7.0' s.summary = 'Utility library that implements clients specific logic to interact with substrate based networks' s.homepage = 'https://github.com/soramitsu/fearless-utils-iOS' diff --git a/FearlessUtils/Classes/Common/StorageKeyFactory.swift b/FearlessUtils/Classes/Common/StorageKeyFactory.swift index b010692..147ccea 100644 --- a/FearlessUtils/Classes/Common/StorageKeyFactory.swift +++ b/FearlessUtils/Classes/Common/StorageKeyFactory.swift @@ -1,6 +1,7 @@ import Foundation public protocol StorageKeyFactoryProtocol { + func createStorageKey(moduleName: String, serviceName: String) throws -> Data func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data } @@ -11,7 +12,7 @@ public enum StorageKeyFactoryError: Error { public struct StorageKeyFactory: StorageKeyFactoryProtocol { public init() {} - public func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data { + public func createStorageKey(moduleName: String, serviceName: String) throws -> Data { guard let moduleKey = moduleName.data(using: .utf8) else { throw StorageKeyFactoryError.badSerialization } @@ -20,11 +21,14 @@ public struct StorageKeyFactory: StorageKeyFactoryProtocol { throw StorageKeyFactoryError.badSerialization } - let moduleKeyHash = moduleKey.xxh128() - let serviceKeyHash = serviceKey.xxh128() + return moduleKey.xxh128() + serviceKey.xxh128() + } + + public func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data { + let subkey = try createStorageKey(moduleName: moduleName, serviceName: serviceName) let identifierHash = try identifier.blake128Concat() - return moduleKeyHash + serviceKeyHash + identifierHash + return subkey + identifierHash } }