@@ -11,6 +11,10 @@ public class KeystoreBuilder {
11
11
}
12
12
13
13
extension KeystoreBuilder : KeystoreBuilding {
14
+ enum Constants {
15
+ static let ethereum = " ethereum "
16
+ }
17
+
14
18
public func with( name: String ) -> Self {
15
19
self . name = name
16
20
return self
@@ -26,7 +30,7 @@ extension KeystoreBuilder: KeystoreBuilding {
26
30
return self
27
31
}
28
32
29
- public func build( from data: KeystoreData , password: String ? ) throws -> KeystoreDefinition {
33
+ public func build( from data: KeystoreData , password: String ? , isEthereum : Bool ) throws -> KeystoreDefinition {
30
34
let scryptParameters = try ScryptParameters ( )
31
35
32
36
let scryptData : Data
@@ -64,17 +68,23 @@ extension KeystoreBuilder: KeystoreBuilding {
64
68
let pcksData = KeystoreConstants . pkcs8Header + secretKeyData +
65
69
KeystoreConstants. pkcs8Divider + data. publicKeyData
66
70
let encrypted = try NaclSecretBox . secretBox ( message: pcksData, nonce: nonce, key: encryptionKey)
71
+
67
72
let encoded = scryptParameters. encode ( ) + nonce + encrypted
68
73
74
+ let cryptoType = isEthereum ? Constants . ethereum : data. cryptoType. rawValue
69
75
let encodingType = [ KeystoreEncodingType . scrypt. rawValue, KeystoreEncodingType . xsalsa. rawValue]
70
- let encodingContent = [ KeystoreEncodingContent . pkcs8. rawValue, data . cryptoType. rawValue ]
76
+ let encodingContent = [ KeystoreEncodingContent . pkcs8. rawValue, cryptoType]
71
77
let keystoreEncoding = KeystoreEncoding ( content: encodingContent,
72
78
type: encodingType,
73
79
version: String ( KeystoreConstants . version) )
74
80
81
+ let isHardware : Bool ? = isEthereum ? false : nil
82
+ let tags : [ String ] ? = isEthereum ? [ ] : nil
75
83
let meta = KeystoreMeta ( name: name,
76
84
createdAt: Int64 ( creationDate. timeIntervalSince1970) ,
77
- genesisHash: genesisHash)
85
+ genesisHash: genesisHash,
86
+ isHardware: isHardware,
87
+ tags: tags)
78
88
79
89
return KeystoreDefinition ( address: data. address,
80
90
encoded: encoded. base64EncodedString ( ) ,
0 commit comments