Skip to content

Commit e586440

Browse files
authored
Merge pull request #58 from soramitsu/restore-json-generation
fix restore json generation
2 parents 38d8d0e + b014ed2 commit e586440

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

FearlessUtils/Classes/Keystore/KeystoreBuilder.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class KeystoreBuilder {
1111
}
1212

1313
extension KeystoreBuilder: KeystoreBuilding {
14+
enum Constants {
15+
static let ethereum = "ethereum"
16+
}
17+
1418
public func with(name: String) -> Self {
1519
self.name = name
1620
return self
@@ -26,7 +30,7 @@ extension KeystoreBuilder: KeystoreBuilding {
2630
return self
2731
}
2832

29-
public func build(from data: KeystoreData, password: String?) throws -> KeystoreDefinition {
33+
public func build(from data: KeystoreData, password: String?, isEthereum: Bool) throws -> KeystoreDefinition {
3034
let scryptParameters = try ScryptParameters()
3135

3236
let scryptData: Data
@@ -64,17 +68,23 @@ extension KeystoreBuilder: KeystoreBuilding {
6468
let pcksData = KeystoreConstants.pkcs8Header + secretKeyData +
6569
KeystoreConstants.pkcs8Divider + data.publicKeyData
6670
let encrypted = try NaclSecretBox.secretBox(message: pcksData, nonce: nonce, key: encryptionKey)
71+
6772
let encoded = scryptParameters.encode() + nonce + encrypted
6873

74+
let cryptoType = isEthereum ? Constants.ethereum : data.cryptoType.rawValue
6975
let encodingType = [KeystoreEncodingType.scrypt.rawValue, KeystoreEncodingType.xsalsa.rawValue]
70-
let encodingContent = [KeystoreEncodingContent.pkcs8.rawValue, data.cryptoType.rawValue]
76+
let encodingContent = [KeystoreEncodingContent.pkcs8.rawValue, cryptoType]
7177
let keystoreEncoding = KeystoreEncoding(content: encodingContent,
7278
type: encodingType,
7379
version: String(KeystoreConstants.version))
7480

81+
let isHardware: Bool? = isEthereum ? false : nil
82+
let tags: [String]? = isEthereum ? [] : nil
7583
let meta = KeystoreMeta(name: name,
7684
createdAt: Int64(creationDate.timeIntervalSince1970),
77-
genesisHash: genesisHash)
85+
genesisHash: genesisHash,
86+
isHardware: isHardware,
87+
tags: tags)
7888

7989
return KeystoreDefinition(address: data.address,
8090
encoded: encoded.base64EncodedString(),

0 commit comments

Comments
 (0)