File tree Expand file tree Collapse file tree 5 files changed +28
-9
lines changed
darwinMain/kotlin/io/eqoty/web3 Expand file tree Collapse file tree 5 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ kotlin.code.style=official
2
2
# kotlin.mpp.enableGranularSourceSetsMetadata=true
3
3
kotlin.native.enableDependencyPropagation =false
4
4
kotlin.mpp.enableCInteropCommonization =true
5
+ kotlin.native.binary.memoryModel =experimental
6
+
5
7
6
8
kotlin.native.cacheKind =none
7
9
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package io.eqoty.web3
2
2
3
3
expect object Web3 {
4
4
5
- fun getAddress (privKey : String ): String
5
+ fun importAccount (privKey : String )
6
+ fun getAddress (): String?
6
7
7
8
}
Original file line number Diff line number Diff line change @@ -4,22 +4,27 @@ import kotlin.test.Test
4
4
import kotlin.test.assertEquals
5
5
6
6
class Web3Tests {
7
+
8
+
7
9
@Test fun `hex prefixed private key to address` () {
8
10
11
+
9
12
val privKey = " 0xeff8ddb99a4fa276e8e70f4c375d99964511b2ac1506ee7e48dcff43d6bc04b9"
13
+ Web3 .importAccount(privKey)
10
14
val expectedAddress = " 0x2AD093baD5b62F51A2145B87bB0F2295b1f9d4Fd" .lowercase()
11
15
12
16
13
- assertEquals(expectedAddress, Web3 .getAddress(privKey) )
17
+ assertEquals(expectedAddress, Web3 .getAddress() )
14
18
}
15
19
16
20
@Test fun `private key to address` () {
17
21
18
22
val privKey = " eff8ddb99a4fa276e8e70f4c375d99964511b2ac1506ee7e48dcff43d6bc04b9"
23
+ Web3 .importAccount(privKey)
19
24
val expectedAddress = " 0x2AD093baD5b62F51A2145B87bB0F2295b1f9d4Fd" .lowercase()
20
25
21
26
22
- assertEquals(expectedAddress, Web3 .getAddress(privKey) )
27
+ assertEquals(expectedAddress, Web3 .getAddress() )
23
28
}
24
29
25
30
}
Original file line number Diff line number Diff line change
1
+ @file:Suppress(" VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL" )
2
+
1
3
package io.eqoty.web3
2
4
3
5
import swift.web3swift.Web3Swift
4
6
5
7
actual object Web3 {
6
- actual fun getAddress (privKey : String ): String {
7
- return Web3Swift .getAddressWithPrivKey(privKey)
8
+ var ethereumAccount: Any? = null
9
+
10
+ actual fun importAccount (privKey : String ) {
11
+ ethereumAccount = Web3Swift .importAccountWithPrivKey(privKey)
8
12
}
9
13
14
+ actual fun getAddress (): String? {
15
+ return Web3Swift .getAddressWithEthereumAccount(ethereumAccount!! )
16
+ }
10
17
11
18
}
Original file line number Diff line number Diff line change 1
1
import Foundation
2
- import CryptoKit
3
2
import web3
4
3
5
4
6
5
@objc public class Web3Swift : NSObject {
7
6
8
- @objc public class func getAddress( privKey: String ) -> String {
7
+
8
+ @objc public class func importAccount( privKey: String ) -> Any {
9
9
let keyStorage = EthereumKeyLocalStorage ( )
10
- let account = try ! EthereumAccount . importAccount ( keyStorage: keyStorage, privateKey: privKey, keystorePassword: " password " )
11
- return account. address. value
10
+ return try ! EthereumAccount . importAccount ( keyStorage: keyStorage, privateKey: privKey, keystorePassword: " password " )
11
+ }
12
+
13
+
14
+ @objc public class func getAddress( ethereumAccount : Any ) -> String ? {
15
+ return ( ethereumAccount as! EthereumAccount ) . address. value
12
16
}
13
17
14
18
}
You can’t perform that action at this time.
0 commit comments