feat(tool): added BIP39 generator
This commit is contained in:
		
							parent
							
								
									93c11f0e44
								
							
						
					
					
						commit
						ecbc5bad28
					
				| @ -25,7 +25,7 @@ import type {ToolConfig} from '@/types/ToolConfig' | ||||
| import Tool from '~/components/Tool.vue' | ||||
| 
 | ||||
| @Component | ||||
| export default class UuidGenerator extends Tool { | ||||
| export default class MyComponent extends Tool { | ||||
|   config(): ToolConfig { | ||||
|     return { | ||||
|       title: 'My component', | ||||
|  | ||||
							
								
								
									
										18
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										18
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -4505,6 +4505,24 @@ | ||||
|         "file-uri-to-path": "1.0.0" | ||||
|       } | ||||
|     }, | ||||
|     "bip39": { | ||||
|       "version": "3.0.3", | ||||
|       "resolved": "https://registry.npmjs.org/bip39/-/bip39-3.0.3.tgz", | ||||
|       "integrity": "sha512-P0dKrz4g0V0BjXfx7d9QNkJ/Txcz/k+hM9TnjqjUaXtuOfAvxXSw2rJw8DX0e3ZPwnK/IgDxoRqf0bvoVCqbMg==", | ||||
|       "requires": { | ||||
|         "@types/node": "11.11.6", | ||||
|         "create-hash": "^1.1.0", | ||||
|         "pbkdf2": "^3.0.9", | ||||
|         "randombytes": "^2.0.1" | ||||
|       }, | ||||
|       "dependencies": { | ||||
|         "@types/node": { | ||||
|           "version": "11.11.6", | ||||
|           "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", | ||||
|           "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==" | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "bluebird": { | ||||
|       "version": "3.7.2", | ||||
|       "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", | ||||
|  | ||||
| @ -16,6 +16,7 @@ | ||||
|     "@nuxtjs/axios": "^5.13.1", | ||||
|     "@nuxtjs/pwa": "^3.0.2", | ||||
|     "@nuxtjs/toast": "^3.3.1", | ||||
|     "bip39": "^3.0.3", | ||||
|     "core-js": "^3.6.5", | ||||
|     "crypto-js": "^4.0.0", | ||||
|     "nuxt": "^2.14.12", | ||||
|  | ||||
							
								
								
									
										110
									
								
								pages/tools/crypto/bip39-generator.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								pages/tools/crypto/bip39-generator.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,110 @@ | ||||
| <template> | ||||
|   <ToolWrapper :config="config()"> | ||||
|     <v-select | ||||
|       v-model="language" | ||||
|       outlined | ||||
|       label="Language" | ||||
|       :items="languageList" | ||||
|       @change="languageChanged" | ||||
|     /> | ||||
|     <v-text-field | ||||
|       ref="entropy" | ||||
|       v-model="entropy" | ||||
|       outlined | ||||
|       label="Entropy" | ||||
|       append-icon="mdi-content-copy" | ||||
|       :rules="rules.entropy" | ||||
|       @click:append="copy(entropy)" | ||||
|     /> | ||||
|     <v-text-field | ||||
|       ref="passphrase" | ||||
|       v-model="passphrase" | ||||
|       outlined | ||||
|       label="Passphrase" | ||||
|       append-icon="mdi-content-copy" | ||||
|       :rules="rules.passphrase" | ||||
|       @click:append="copy(passphrase)" | ||||
|     /> | ||||
|     <div class="text-center"> | ||||
|       <v-btn @click="refresh"> | ||||
|         refresh | ||||
|       </v-btn> | ||||
|     </div> | ||||
|   </ToolWrapper> | ||||
| </template> | ||||
| 
 | ||||
| <script lang="ts"> | ||||
| import * as bip39 from 'bip39' | ||||
| import {shuffle} from '@/utils/string' | ||||
| import {Component, Ref} from 'nuxt-property-decorator' | ||||
| import {CopyableMixin} from '@/mixins/copyable.mixin' | ||||
| import Tool from '@/components/Tool.vue' | ||||
| import {ToolConfig} from '@/types/ToolConfig' | ||||
| import type {VForm} from '~/types/VForm' | ||||
| 
 | ||||
| const getRandomBuffer = () => Buffer.from(shuffle('0123456789abcdef'.repeat(16)).substring(0, 32), 'hex') | ||||
| 
 | ||||
| @Component({ | ||||
|   mixins: [CopyableMixin] | ||||
| }) | ||||
| export default class Bip39Generator extends Tool { | ||||
|   config(): ToolConfig { | ||||
|     return { | ||||
|       title: 'BIP39 passphrase generator', | ||||
|       description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus distinctio dolor dolorum eaque eligendi, facilis impedit laboriosam odit placeat.', | ||||
|       icon: 'mdi-message-text-lock-outline', | ||||
|       keywords: ['BIP39', 'passphrase', 'generator'] | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Ref() readonly entropyRef!: VForm | ||||
|   @Ref() readonly passphraseRef!: VForm | ||||
|   buffer = getRandomBuffer() | ||||
|   language: string = 'english' | ||||
|   languageList = Object | ||||
|     .keys(bip39.wordlists) | ||||
|     .filter(k => !k.match(/[A-Z]{2}/)) | ||||
|     .map(k => ({ | ||||
|       text: k.split('_').map(k => k.charAt(0).toUpperCase() + k.slice(1)).join(' '), | ||||
|       value: k | ||||
|     })) | ||||
| 
 | ||||
|   rules = { | ||||
|     passphrase: [(v: string | undefined) => (!!v && bip39.validateMnemonic(v)) || 'Invalid mnemonic.'], | ||||
|     entropy: [(v: string | undefined) => (!!v && !!v.match(/[0-9a-fA-F]{32}/)) || 'Invalid entropy.'] | ||||
|   } | ||||
| 
 | ||||
|   get entropy() { | ||||
|     return this.buffer.toString('hex') | ||||
|   } | ||||
| 
 | ||||
|   set entropy(value) { | ||||
|     if (this.entropyRef.validate()) { | ||||
|       this.buffer = Buffer.from(value, 'hex') | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   get passphrase() { | ||||
|     return bip39.entropyToMnemonic(this.buffer) | ||||
|   } | ||||
| 
 | ||||
|   set passphrase(value) { | ||||
|     if (this.passphraseRef.validate()) { | ||||
|       this.buffer = Buffer.from(bip39.mnemonicToEntropy(value), 'hex') | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   refresh() { | ||||
|     this.buffer = getRandomBuffer() | ||||
|   } | ||||
| 
 | ||||
|   languageChanged() { | ||||
|     bip39.setDefaultWordlist(this.language) | ||||
|     this.passphrase = bip39.entropyToMnemonic(this.buffer) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| </script> | ||||
| 
 | ||||
| <style scoped> | ||||
| </style> | ||||
							
								
								
									
										2
									
								
								types/VForm.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								types/VForm.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| 
 | ||||
| export type VForm = Vue & { validate: () => boolean } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user