Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
feat: release ready (#337)
Browse files Browse the repository at this point in the history
* feat: upgraded to sdk version 37

* feat: updated type to include keysigning pair

* feat: updated the dev tools too include the signing key pair

* feat: added new buttno for advanced options can select new keypair type

* feat: added new field keysigning pair to the state

* fix: removed console log in coded

* feat: release candidate added

* feat: removed untested signing key pair types

* feat: upated to the latest release candidate
  • Loading branch information
Dudleyneedham authored Mar 9, 2021
1 parent f1156ff commit 3904664
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 198 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@babel/core": "^7.10.4",
"@kiltprotocol/sdk-js": "^0.19.1-34",
"@kiltprotocol/sdk-js": "^0.20.0-rc.2",
"@polkadot/ui-identicon": "^0.33.1",
"@types/react-select": "^2.0.11",
"@types/reselect": "^2.2.0",
Expand Down
4 changes: 3 additions & 1 deletion src/components/DevTools/DevTools.anticov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ let cachedSetup: ISetup

function setup(): ISetup {
if (!cachedSetup) {
const root = Identity.buildFromMnemonic(ROOT_SEED)
const root = Identity.buildFromMnemonic(ROOT_SEED, {
signingKeyPairType: 'ed25519',
})

const delegationRoot = new DelegationRootNode(
DELEGATION_ROOT_ID,
Expand Down
4 changes: 3 additions & 1 deletion src/components/DevTools/DevTools.wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class BsIdentity {

public static async create(alias: string): Promise<void | IMyIdentity> {
const randomPhrase = mnemonicGenerate()
const identity = Identity.buildFromMnemonic(randomPhrase)
const identity = Identity.buildFromMnemonic(randomPhrase, {
signingKeyPairType: 'ed25519',
})

return BsIdentity.save(identity, randomPhrase, alias)
}
Expand Down
68 changes: 65 additions & 3 deletions src/containers/WalletAdd/WalletAdd.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Identity } from '@kiltprotocol/sdk-js'
import * as mnemonic from '@polkadot/util-crypto/mnemonic'
import { KeypairType } from '@polkadot/util-crypto/types'
import React from 'react'
import { connect } from 'react-redux'
import { RouteComponentProps } from 'react-router'
import { Link, withRouter } from 'react-router-dom'
import Select from 'react-select'
import DidService from '../../services/DidService'

import Input from '../../components/Input/Input'
import { BalanceUtilities } from '../../services/BalanceUtilities'
import ContactRepository from '../../services/ContactRepository'
Expand All @@ -18,6 +19,11 @@ import { IContact, IMyIdentity } from '../../types/Contact'

import './WalletAdd.scss'

type OptionsKeyPairType = {
label: string
value: KeypairType
}

type DispatchProps = {
saveIdentity: (myIdentity: IMyIdentity) => void
}
Expand All @@ -30,26 +36,44 @@ type State = {
randomPhrase: string
useMyPhrase: boolean
myPhrase: string
mySigningKeyPairType: OptionsKeyPairType
advancedOptions: boolean
}

const keypairTypeOptions: OptionsKeyPairType[] = [
{ value: 'sr25519', label: 'SR25519' },
{ value: 'ed25519', label: 'ED25519' },
]

class WalletAdd extends React.Component<Props, State> {
constructor(props: Props) {
super(props)
this.state = {
alias: '',
myPhrase: '',
mySigningKeyPairType: keypairTypeOptions[0],
pendingAdd: false,
randomPhrase: mnemonic.mnemonicGenerate(),
useMyPhrase: false,
advancedOptions: false,
}
this.togglePhrase = this.togglePhrase.bind(this)
this.toggleAdvancedOptions = this.toggleAdvancedOptions.bind(this)
this.addIdentity = this.addIdentity.bind(this)
}

private setMyPhrase = (e: React.ChangeEvent<HTMLInputElement>): void => {
this.setState({ myPhrase: e.currentTarget.value })
}

private setMySigningKeyPairType = (
selectedKeyPairType: OptionsKeyPairType
): void => {
this.setState({
mySigningKeyPairType: selectedKeyPairType,
})
}

private setAlias = (e: React.ChangeEvent<HTMLInputElement>): void => {
this.setState({ alias: e.currentTarget.value })
}
Expand All @@ -65,14 +89,29 @@ class WalletAdd extends React.Component<Props, State> {
})
}

private toggleAdvancedOptions(): void {
const { advancedOptions } = this.state
this.setState({
advancedOptions: !advancedOptions,
})
}

private async addIdentity(): Promise<void> {
const { alias, myPhrase, randomPhrase, useMyPhrase } = this.state
const {
alias,
myPhrase,
randomPhrase,
useMyPhrase,
mySigningKeyPairType,
} = this.state
const { history, saveIdentity } = this.props

let identity
const phrase = useMyPhrase ? myPhrase : randomPhrase
try {
identity = Identity.buildFromMnemonic(phrase)
identity = Identity.buildFromMnemonic(phrase, {
signingKeyPairType: mySigningKeyPairType.value,
})
} catch (error) {
errorService.log({
error,
Expand All @@ -87,6 +126,7 @@ class WalletAdd extends React.Component<Props, State> {

const newIdentity: IMyIdentity = {
identity,
keypairType: mySigningKeyPairType.value,
metaData: {
name: alias,
},
Expand Down Expand Up @@ -123,7 +163,10 @@ class WalletAdd extends React.Component<Props, State> {
pendingAdd,
useMyPhrase,
myPhrase,
advancedOptions,
mySigningKeyPairType,
} = this.state

return (
<section className="WalletAdd">
<h1>Create ID</h1>
Expand Down Expand Up @@ -177,6 +220,25 @@ class WalletAdd extends React.Component<Props, State> {
Import Seed Phrase
</div>

<div className="actions">
<button type="button" onClick={this.toggleAdvancedOptions}>
Advanced Options
</button>
</div>

{advancedOptions && (
<div className="key-pair-type">
<label>Signing Key Pair</label>
<div>
<Select
options={keypairTypeOptions}
value={mySigningKeyPairType}
onChange={this.setMySigningKeyPairType}
/>
</div>
</div>
)}

<div className="actions">
<Link className="cancel" to="/wallet">
Cancel
Expand Down
9 changes: 7 additions & 2 deletions src/state/ducks/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type SerializedIdentity = {
did?: IMyIdentity['did']
name: IMyIdentity['metaData']['name']
phrase: IMyIdentity['phrase']
keypairType: IMyIdentity['keypairType']
createdAt?: IMyIdentity['createdAt']
}

Expand All @@ -61,6 +62,7 @@ class Store {
createdAt: myIdentity.createdAt,
did: myIdentity.did,
name: myIdentity.metaData.name,
keypairType: myIdentity.keypairType,
phrase: myIdentity.phrase,
}))
.toArray()
Expand All @@ -85,11 +87,13 @@ class Store {
const identities: { [key: string]: IMyIdentity } = {}

serializedIdentities.forEach((serializedIdentity: SerializedIdentity) => {
const { did, name, phrase, createdAt } = serializedIdentity
const { did, name, phrase, createdAt, keypairType } = serializedIdentity

// TODO: use real wallet later instead of stored phrase

const identity = Identity.buildFromMnemonic(phrase)
const identity = Identity.buildFromMnemonic(phrase, {
signingKeyPairType: keypairType,
})

const myIdentity: IMyIdentity = {
createdAt,
Expand All @@ -99,6 +103,7 @@ class Store {
name,
},
phrase,
keypairType,
}

identities[identity.address] = myIdentity
Expand Down
2 changes: 2 additions & 0 deletions src/types/Contact.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Identity, PublicIdentity } from '@kiltprotocol/sdk-js'
import { IDidDocument } from '@kiltprotocol/types'
import { KeypairType } from '@polkadot/util-crypto/types'

/**
* as in prototype/services
Expand All @@ -24,6 +25,7 @@ export interface IContact {
*/
export interface IMyIdentity {
identity: Identity
keypairType: KeypairType
metaData: {
name: string
}
Expand Down
Loading

0 comments on commit 3904664

Please sign in to comment.