THe RSK Key Management System library is to assist developers to easily interact with the RSK blockchain and its ecosystem. The goal is to build a general-purpose library around the core functionalities of the RSK blockchain.
- Keep your private keys in your client, safe and sound
- Import and export JSON wallets
- Import and export BIP 39 mnemonic phrases (12 word backup phrases) and HD Wallets
- Connect to RSK nodes over JSON-RPC
- Complete functionality for all your RSK needs
- Comprehensive documentation
- Large collection of test cases which are maintained and added to
- Fully Open Sourced
The RSK Key Management System library is built with a 3 layer architecture.
- The Base Layer enableds wallet(private keys) to be stored in secure enclave and hardware device. It also provides ways to store, protect, access and recovery wallets.
- The Middle Layer provides API Interpreter for all typical actions, including transactions, smart contract operations, sign/verify messages, as well as common utilities. The Middle Layer sends request to base layer for verification and signing.
- The Top Layer provides API Interfaces to popular programming languages (JS, Python, etc) and also connects to provider handlers.
The RSK Key Management base layer consists of a secure environment with the protocol and processes for accessing the RSK Wallet for: private key seed generation, key storage, protection, import, export, and recovery, in addition to key signing and signature verification. The base layer is directly accessed through the Middle and indirectly through the Top Layer.
It will extend itself in the future to support multiple hardware wallets used for a single multi-signature keyset, for example the creation of 2of3 multisig keysets using 3 ledger wallets.
It will also extend itself in the future to support key derivation for various RSK/RIF services offered, including Single Sign-on, RNS, Encryption & Private communication and so on.
The RSK Key Management Mid Layer role in key management is to be the gatekeeper of knowledge and interaction with the Base Layer for processing requests, events and actions that require signature verification, signing, transaction, smart contract operation, along with requesting storage, importing, and recovery of keys. It also provides modules for ABI (Application Binary Interface) Coding for working with smart contracts, along with Utilities which allow for a range of common functions required for dapps, processing input from users and formatting data.
The API Interpreter provides an interface between the Base and Top Layers to communicate requests and return their outputs seamlessly, enabling top layer dapps, browsers and applications to interact with the processes.
- New Wallet
- BIP-039+BIP-044 wallet derived path using a wordlist
- Connect (provider)
- Developers want users to sign messages using solidity validation, client code to sign a message, client code to call solidity validation. Ref on Security for Signing and Verifying Signatures: https://dzone.com/articles/signing-and-verifying-ethereum-signatures
- signMessage (message)
- sign (transaction)
- to, gasLimit, gasPrice, nonce, data, value, chainId
- Nonces: Signed messages should contain a nonce of some kind to mitigate against replay attacks.
- Ecrecover (based on https://github.com/sogoiii/ecrecover-example)
- Solidity provides a globally available method ecrecover that returns an address. If the return address is the same as the signer, then the signature is real.
- recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s
- returns (address)
- isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool)
- return ecrecover(msgHash, v, r, s) == _addr;
- SigningKey(priv Key)
- Create a new SigningKey and compute corresponding pubkey & address
- signDigest (messageDigest)
- Compute ECDH shared secret from the keys pKey and publicOrPrivateKey (good practice: hash this value before using it as a key)
- SigningKey(priv Key)
- mnemonic-path (mnemonic path for a wallet)
- Create & Deploy a Contract
- Connect to Existing Contracts
- View existing contract details
- Contract Event Filters
- Event Emitters (Naming, Objects, Configuration)
- Types (Bytes, Integers, Strings, Structs)
- Filtering Events
- Application Binary Interface (ABI)
- Big Numbers
- Byte32 Strings
- Cryptographic Functions
- Elliptic Curve, Hash Functions & Helpers, Key Derivation, Random, Solidity
- Hex Strings (eg. toHex)
- UTF-8 Strings
- Transactions: Serialize a transaction & Parse a serialized transaction
- Create ABI Coder & Interface
- encode & decode
- Interface (abi)
- Return new instance and populate properties with ABI constructor, methods and events. The abi can be a JSON string or parsed JSON object.
- An object of all the events available in the ABI
- An object of all the functions available in the ABI
The RSK Key Management Top Layer provides Account Management interfaces, API interfaces (Python, JS) and Provider handler to interact with RSK provider networks (Local, Public, and 3rd party operated).
- Account Manager
- API Interfaces
|create_wallet||Create a wallet with a label & master encrypted passphrase choose between using a hardware wallet, generating keystore file or a mnemonic phrase.
|set_wallet_label||Sets the local wallet label to a new label.
|import_wallet||Import existing wallet’s accounts as a new Wallet using a private key or encrypted JSON keystore
|recover_wallet_mnemonic||Recover a wallet using a mnemonic phrase|
|export||Export the keyset for a wallet|
|get_dev_coins [RIF or RBTC]||Quickly get rBTC or RIF testnet funds from faucets. (Only works if you are connected to RSK-Testnet. )
|contract_create||Creates a new contract instance with all methods and events defined in the interface
|contract_method||Create a transaction object for a method that can be called, sent, estimated|
|ttcontract_event_subscribe_once||Subscribes to an event only once|
|contract_event_subscribe||Subscribes to an event|
|contract_allevents||Receives all events from this smart contract, or filter events.|
|contract_pastevents||Gets past events for this contract.|
|view_accounts||Show accounts for existing wallet using a variety of methods [ hardware, web3, private key, keystore, mnemonic]
|get_balance||Get balance of accounts in a wallet, or specify a specific account
|pay, payment||to, amount, account from, fee|
|paytomany||Pay to many|
|signMsg, signTx||Signing of messages or transactions
|check_tx_status||Check the transaction status of a txID|
|build_tx||build_tx (account, amount, gas, nonce, gasPrice, data)|
|send_tx||Sends a signed transaction
Additional Multicurrency Addresses
The above example interfaces aim at being sufficient to allow a developer to connect to a provider, create or import a wallet, build a smart contract, receive faucet tokens, sign a transaction, and send a transaction, which would in effect deploy the contract. These can be expanded upon and should be.
- python-rsk library
- Provider Handlers
- These handlers ease the connection process and data passing between the RSK Public or local node networks and the mid and base layer processes.
The RSK Providers are the Networks themselves, consisting of node operators, federation members and miners that support the operation of the RSK networks. It also includes locally run nodes, public nodes, test networks, explorers, 3rd party wallets, and faucets.