GithubHelp home page GithubHelp logo

isabella232 / keystore.swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boilertalk/keystore.swift

0.0 0.0 0.0 602 KB

Ethereum keystore creation / private key extraction for Swift

License: MIT License

Swift 96.13% Ruby 3.87%

keystore.swift's Introduction

CI Status Version License Platform Carthage compatible Telegram

⚗️ Keystore

Keystore.swift makes it easy to extract private keys from Ethereum keystore files and generate keystore files from existing private keys.
This library belongs to our Swift Crypto suite. For a pure Swift Ethereum Web3 library check out Web3.swift!

Example

Check the usage below or look through the repositories tests.

Installation

CocoaPods

Keystore is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Keystore'

Carthage

Keystore is compatible with Carthage, a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To install it, simply add the following line to your Cartfile:

github "Boilertalk/Keystore.swift"

You will also have to install the dependencies, which can be found in our Cartfile.

Swift Package Manager

Keystore is compatible with Swift Package Manager v4 (Swift 4 and above). Simply add it to the dependencies in your Package.swift.

dependencies: [
    .package(url: "https://github.com/Boilertalk/Keystore.swift.git", from: "0.2.0")
]

And then add it to your target dependencies:

targets: [
    .target(
        name: "MyProject",
        dependencies: ["Keystore"]),
    .testTarget(
        name: "MyProjectTests",
        dependencies: ["MyProject"])
]

After the installation you can import Keystore in your .swift files.

import Keystore

Usage

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 key

And 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 string

Author

The awesome guys at Boilertalk ⚗️
...and even more awesome members from the community 💜

Check out the contributors list for a complete list.

License

Keystore is available under the MIT license. See the LICENSE file for more info.

keystore.swift's People

Contributors

koraykoska avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.