Boilertalk/Keystore.swift
Ethereum and ETH2 (BLS) keystore creation / private key extraction for Swift
Example
Check the usage below or look through the repositories tests.
Installation
We only support Swift Package Manager. Everything else is outdated.
Swift Package Manager
Keystore is compatible with Swift Package Manager v5 (Swift 5 and above). Simply add it to the dependencies in your Package.swift.
dependencies: [
.package(url: "https://github.com/Boilertalk/Keystore.swift.git", from: "0.3.0")
]And then add it to your target dependencies:
targets: [
.target(
name: "MyProject",
dependencies: [
.product(name: "Keystore", package: "Keystore.swift"),
]),
.testTarget(
name: "MyProjectTests",
dependencies: ["MyProject"])
]After the installation you can import Keystore in your .swift files.
import KeystoreUsage
ETH1 / Normal Keystore
To extract a private key from an existing keystore file, just do the following.
import Keystore
let decoder = JSONDecoder()
let keystoreData: Data = ... // Load keystore data from file?
let keystore = try decoder.decode(Keystore.self, from: keystoreData)
let password = "your_super_secret_password"
let privateKey = try keystore.privateKey(password: password)
print(privateKey) // Your decrypted private keyAnd to generate a keystore file from an existing private key, your code should look a little bit like the following.
let privateKey: [UInt8] = ... // Get your private key as a byte array
let password = "your_super_secret_password"
let keystore = try Keystore(privateKey: privateKey, password: password)
let keystoreJson = try JSONEncoder().encode(keystore)
print(String(data: keystoreJson, encoding: .utf8)) // Your encrypted keystore as a json stringETH2 / BLS Keystore
To extract a private key from an existing keystore file, just do the following.
import Keystore
let decoder = JSONDecoder()
let keystoreData: Data = ... // Load keystore data from file?
let keystore = try decoder.decode(KeystoreETH2.self, from: keystoreData)
let password = "your_super_secret_password"
let privateKey = try keystore.privateKey(password: password)
print(privateKey) // Your decrypted private keyLicense
Keystore is available under the MIT license. See the LICENSE file for more info.
Package Metadata
Repository: Boilertalk/Keystore.swift
Stars: 18
Forks: 7
Open issues: 6
Default branch: master
Primary language: swift
License: MIT
Topics: bls, eip2335, eth2, ethereum, keystore, swift, web3
README: README.md