Skip to content

Commit 506f5eb

Browse files
committed
Create basic component to generate seeds, keys and addresses
1 parent 23bb3fb commit 506f5eb

File tree

6 files changed

+116
-2
lines changed

6 files changed

+116
-2
lines changed

packages/kauri-wallet/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h1>
33
{{ title }}
44
</h1>
5-
5+
<app-generate-master-xpriv-key></app-generate-master-xpriv-key>
66
<app-translation-sample></app-translation-sample>
77
<app-sw-update-prompt></app-sw-update-prompt>
88
<app-api-sample></app-api-sample>

packages/kauri-wallet/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import { ApiService } from './services/api/api.service';
1212
import { WalletComponent } from './wallet/wallet.component';
1313
import { HttpClientModule } from '@angular/common/http';
1414
import { DataService } from './services/data/data.service';
15+
import { GenerateMasterXPrivKeyComponent } from './features/addresses/generate-master-xpriv-key/generate-master-xpriv-key.component';
1516

1617
@NgModule({
1718
declarations: [
1819
AppComponent,
1920
TranslationSampleComponent,
2021
SwUpdatePromptComponent,
21-
WalletComponent
22+
WalletComponent,
23+
GenerateMasterXPrivKeyComponent
2224
],
2325
imports: [
2426
BrowserModule,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div>
2+
<h2>Seed Phrase</h2>
3+
<h4>This is a demo. It is insecure. Not not enter your real seed phrase!!!</h4>
4+
<p>
5+
Seed: <br />
6+
<code>{{seed}}</code>
7+
</p>
8+
Enter seed: <input #userSeed /> <button (click)="updateSeed(userSeed.value)">Save</button>
9+
<br />
10+
<button (click)="generateSeed()">Generate seed</button>
11+
12+
<h2>Master Private Keys</h2>
13+
BTC <br />
14+
{{masterkeys.btc}} <br /><br/>
15+
NAV <br />
16+
{{masterkeys.nav}} <br /><br />
17+
18+
<h2>Addresses</h2>
19+
<h3>btc</h3>
20+
<ul>
21+
<li *ngFor="let address of addresses.btc">
22+
{{ address.toString() }}
23+
</li>
24+
</ul>
25+
<h3>nav</h3>
26+
<ul>
27+
<li *ngFor="let address of addresses.nav">
28+
{{ address.toString() }}
29+
</li>
30+
</ul>
31+
</div>

packages/kauri-wallet/src/app/features/addresses/generate-master-xpriv-key/generate-master-xpriv-key.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { GenerateMasterXPrivKeyComponent } from './generate-master-xpriv-key.component';
4+
5+
describe('GenerateMasterXPrivKeyComponent', () => {
6+
let component: GenerateMasterXPrivKeyComponent;
7+
let fixture: ComponentFixture<GenerateMasterXPrivKeyComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ GenerateMasterXPrivKeyComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(GenerateMasterXPrivKeyComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import * as bip39 from 'bip39';
3+
import * as Bitcore from 'kauri-bitcore-lib';
4+
5+
@Component({
6+
selector: 'app-generate-master-xpriv-key',
7+
templateUrl: './generate-master-xpriv-key.component.html',
8+
styleUrls: ['./generate-master-xpriv-key.component.scss']
9+
})
10+
export class GenerateMasterXPrivKeyComponent implements OnInit {
11+
12+
seed = '';
13+
masterkeys = {
14+
btc: '',
15+
nav: '',
16+
};
17+
addresses = {
18+
btc: [],
19+
nav: [],
20+
};
21+
22+
constructor() { }
23+
24+
ngOnInit() {
25+
}
26+
27+
generateSeed() {
28+
this.seed = bip39.generateMnemonic(256);
29+
this.createMasterKeys();
30+
}
31+
32+
updateSeed(userSeed) {
33+
this.seed = userSeed;
34+
this.createMasterKeys();
35+
}
36+
37+
createMasterKeys() {
38+
this.masterkeys.btc = Bitcore.HDPrivateKey.fromSeed(bip39.mnemonicToSeedHex(this.seed), 'BTCmainnet');
39+
this.masterkeys.nav = Bitcore.HDPrivateKey.fromSeed(bip39.mnemonicToSeedHex(this.seed), 'NAVmainnet');
40+
this.removeOldAddresss();
41+
this.generateAddresses();
42+
}
43+
44+
removeOldAddresss() {
45+
this.addresses.btc = [];
46+
this.addresses.nav = [];
47+
}
48+
49+
generateAddresses() {
50+
for (let i = 0; i < 5; i++) {
51+
// m / purpose' / coin_type' / account' / change / address_index
52+
this.addresses.btc.push(this.masterkeys.btc.deriveChild(`m/44'/0'/0'/0/${i}`).privateKey.toAddress('BTCmainnet'));
53+
this.addresses.nav.push(this.masterkeys.nav.deriveChild(`m/44'/160'/0'/0/${i}`).privateKey.toAddress('NAVmainnet'));
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)