dotkey

command module
v0.0.0-...-478f857 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

dotkey

dotkey is a command line interface (CLI) wallet to generate polkadot (and other associated networks such as Kusama) keys using mnemonics. Also sign and verify data using these keys.

disclaimer

The use of this tool does not guarantee security or usability for any particular purpose. Please review the code and use at your own risk.

installation

This step assumes you have Go compiler toolchain installed on your system.

Download this repo to a folder and cd to it.

go install

Add autocompletion for bash to your .bashrc

source <(dotkey completion bash)

generate keys

Polkadot keys can be generated using mnemonic. bip39 can be used for generating new mnemonics:

bip39 gen
patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
dotkey gen
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
pub: 5Dkq59KEs7FZB6rJs4ANd6q3gBitt2o3zYEBGtdnApWWFyUq
prv: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr

The public key contains one byte of network identifier (first byte) and two bytes of checksum (last two bytes). It is, therefore, possible to generate different public keys for different networks maintaining the same private key.

The default network is called substrate. To generate key for polkadot relay chain, provide network name as polkadot:

dotkey gen --network=polkadot
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
pub: 12h8DUaJitX2cdrpphDNmFfCXoiYaLMC52xfSBd8iuY2SAFj
prv: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr

Alternatively, network hex value can be used instead of name. See dotkey list-networks command below to get networks associated with polkadot

dotkey gen --network=00
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
pub: 12h8DUaJitX2cdrpphDNmFfCXoiYaLMC52xfSBd8iuY2SAFj
prv: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr

As you can see the private keys are the same, but public keys are different. This makes it possible to validate signature using either of the public keys.

The keys are expected to match those generated by Polkadot{.js} Extension Wallet and subkey CLI, although without use of any key derivation at the moment.

Keys can be additionally protected using a passphrase:

dotkey gen --use-passphrase 
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
Enter secret passphrase: 
Enter secret passphrase again: 
pub: 5FCd9xST9cDztp1JGgfYHARXSod32fmhVThUWZCGobdv8iR6
prv: CNJH7EXH1wojTP5LiGgr8xaBMWgrFzUbX5YfypbXNtfW

Mnemonic is validated and expected to comply to BIP-39 standard. Only english language mnemonic is supported at this point. Mnemonic validation can be skipped, however, this loses any randomness entropy guarantees that comes inherently with valid mnemonics

dotkey gen --skip-mnemonic-validation
Enter mnemonic: this is an invalid mnemonic
seed: bb06e6570ed0b71ac71e4feefeb3a7e2e4cf04ba80a065408150800f86583add8d7ba2ed117444a00f95ca8966ea2e7ff5c8a84b0f5b35a43388d76f0eca043f
pub: 5GuTxFB8TmXTsqL9iXtkdeUG1WEAfVs4awiWfbCUJFVAu4or
prv: 3szkxPjR8u52uWfgJPtGdzVqdjozRSPptHvkfKYUaUsq

Cryptographic schemes can be changed to either Ed25519 or Sr25519:

dotkey gen --scheme=ed25519
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
seed: 19907c1f84128f620218695308fb9dd97742baaaa832cdcf18e763b516fd5769
pub: 5DTatDjH59QYHLBgzvXFxkvbV1JskwmzXydiC8hQd2qmAiei
prv: WePVryNYi198dbiRSpLmMN2NALW23V7Mm2XMXWjcVZCn5qz9f4RJfSJFxmWyybM7ZQDJL1xTsNodZVMBETSNCy9

dotkey gen --scheme=sr25519
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
seed: 19907c1f84128f620218695308fb9dd97742baaaa832cdcf18e763b516fd5769fce6f5b16c2790d12153a5867aa4f1b3ccfddf2499183a68b2d855a18502be04
pub: 5Dkq59KEs7FZB6rJs4ANd6q3gBitt2o3zYEBGtdnApWWFyUq
prv: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr

validate keys

Key validation checks for key string format, length and other characteristics. For instance, if a private key is entered, it also checks if a public key can be derived from it.

Generate keys for both sr25519 and ed25519 schemes

dotkey gen --scheme=sr25519
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
pub: 5Dkq59KEs7FZB6rJs4ANd6q3gBitt2o3zYEBGtdnApWWFyUq
prv: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr

dotkey gen --scheme=ed25519
Enter mnemonic: patient board palm abandon right sort find blood grace sweet vote load action bag trash calm burden glow phrase shoot frog vacant elegant tourist
pub: 5DTatDjH59QYHLBgzvXFxkvbV1JskwmzXydiC8hQd2qmAiei
prv: WePVryNYi198dbiRSpLmMN2NALW23V7Mm2XMXWjcVZCn5qz9f4RJfSJFxmWyybM7ZQDJL1xTsNodZVMBETSNCy9

These keys can be validated:

dotkey validate 
Enter prv or pub key: 5Dkq59KEs7FZB6rJs4ANd6q3gBitt2o3zYEBGtdnApWWFyUq
sr25519 public key for network substrate is valid

dotkey validate 
Enter prv or pub key: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr
sr25519 private key is valid

dotkey validate 
Enter prv or pub key: 5DTatDjH59QYHLBgzvXFxkvbV1JskwmzXydiC8hQd2qmAiei
ed25519 public key for network substrate is valid

dotkey validate 
Enter prv or pub key: WePVryNYi198dbiRSpLmMN2NALW23V7Mm2XMXWjcVZCn5qz9f4RJfSJFxmWyybM7ZQDJL1xTsNodZVMBETSNCy9
ed25519 private key is valid

sign input

Sign arbitrary data using private key. Signing allows someone to verify the signature using public key. Signing generates Keccak256 hash of the input data.

Sign using ed25519 key:

dotkey sign this arbitrary input
Enter prv key: WePVryNYi198dbiRSpLmMN2NALW23V7Mm2XMXWjcVZCn5qz9f4RJfSJFxmWyybM7ZQDJL1xTsNodZVMBETSNCy9
hash:  9PW5sgZmMnaBYgJxUQASyDQoeKoxPcgBLvCJEHVEFqb5
sign:  25Kou6uePUPTvvAWw7jYGYjKQTwZQWVZd3LEqsqL3NtCwmj554nYtXYcay3QnW96gmQLLHuGUoXScL8Zy9hJU8pP

Or using sr25519 key. It infers the type of key used based on key length.

dotkey sign this arbitrary input
Enter prv key: 8bJUC1kRPrMdsjYhnZbd5sSDfxhYgYDJFpUnNwKNndQr
hash:  9PW5sgZmMnaBYgJxUQASyDQoeKoxPcgBLvCJEHVEFqb5
sign:  4LF5Tamx6zqUJNPh6yCp9FsFCWd1KBXa824tqriQAg9gCkqZgxMh4UeEvp3pzfMFiLKMgRYYPLVkNZgGSV9MRw7N

verify signature

Similarly, depending on whether sr25519 or ed25519 key was used, the corresponding public key can be used to verify signature:

dotkey verify 
Enter pub key: 5DTatDjH59QYHLBgzvXFxkvbV1JskwmzXydiC8hQd2qmAiei
Enter hash: 9PW5sgZmMnaBYgJxUQASyDQoeKoxPcgBLvCJEHVEFqb5
Enter sign: 25Kou6uePUPTvvAWw7jYGYjKQTwZQWVZd3LEqsqL3NtCwmj554nYtXYcay3QnW96gmQLLHuGUoXScL8Zy9hJU8pP
signature is valid for given hash and public key
dotkey verify 
Enter pub key: 5Dkq59KEs7FZB6rJs4ANd6q3gBitt2o3zYEBGtdnApWWFyUq
Enter hash: 9PW5sgZmMnaBYgJxUQASyDQoeKoxPcgBLvCJEHVEFqb5
Enter sign: 4LF5Tamx6zqUJNPh6yCp9FsFCWd1KBXa824tqriQAg9gCkqZgxMh4UeEvp3pzfMFiLKMgRYYPLVkNZgGSV9MRw7N
signature is valid for given hash and public key

generate hash

Keccak256 hash can be generated for the input

dotkey hash this arbitrary input
hash:  9PW5sgZmMnaBYgJxUQASyDQoeKoxPcgBLvCJEHVEFqb5

list networks

Since public keys are specific to polkadot networks, the available networks can be listed as follows:

dotkey list-networks
https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
  PREFIX           NAME           
---------+------------------------
  0x00     polkadot               
  0x01     baresr25519            
  0x02     kusama                 
  0x03     bareed25519            
  0x04     katalchain             
  0x04     moonbeam               
  0x05     moonriver              
  0x05     astar                  
  0x06     bifrost                
  0x07     edgeware               
  0x08     karura                 
  0x09     reynolds               
  0x0a     acala                  
  0x0b     laminar                
  0x0c     polymesh               
  0x0c     pioneer_network        
  0x0d     integritee             
  0x0e     totem                  
  0x0f     synesthesia            
  0x10     kulupu                 
  0x11     dark                   
  0x12     darwinia               
  0x13     geek                   
  0x14     stafi                  
  0x15     dock-testnet           
  0x16     dock-mainnet           
  0x17     shift                  
  0x18     zero                   
  0x19     zero-alphaville        
  0x1a     jupiter                
  0x1b     kabocha                
  0x1c     subsocial              
  0x1d     cord                   
  0x1e     phala                  
  0x1f     litentry               
  0x20     robonomics             
  0x21     datahighway            
  0x22     ares                   
  0x23     vln                    
  0x24     centrifuge             
  0x25     nodle                  
  0x26     kilt                   
  0x27     mathchain              
  0x28     mathchain-testnet      
  0x29     poli                   
  0x2a     substrate              
  0x2b     baresecp256k1          
  0x2c     kintsugi               
  0x2c     chainx                 
  0x2c     contextfree            
  0x2d     uniarts                
  0x2e     reserved46             
  0x2f     reserved47             
  0x30     neatcoin               
  0x31     picasso                
  0x32     composable             
  0x33     oak                    
  0x34     kico                   
  0x35     dico                   
  0x37     xxnetwork              
  0x39     ajuna                  
  0x39     basilisk               
  0x3f     hydradx                
  0x41     aventus                
  0x42     crust                  
  0x42     cess-testnet           
  0x43     cess                   
  0x43     genshiro               
  0x44     equilibrium            
  0x45     sora                   
  0x49     zeitgeist              
  0x4d     manta                  
  0x4e     calamari               
  0x56     efinity                
  0x58     polkadex               
  0x62     polkasmith             
  0x63     polkafoundry           
  0x65     origintrail-parachain  
  0x69     pontem-network         
  0x6e     heiko                  
  0x71     integritee-incognito   
  0x80     clover                 
  0x83     litmus                 
  0x88     altair                 
  0xa4     sora_kusama_para       
  0xac     parallel               
  0xce     subspace               
  0xce     subspace_testnet       
  0xd7     kapex                  
  0xf0     interlay               
  0xfc     social-network         
  0xff     quartz_mainnet         

Documentation

Overview

Copyright © 2022 kubetrail.io authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg
run

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL