Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor enhancements #135

Merged
merged 12 commits into from
Sep 20, 2022
5 changes: 1 addition & 4 deletions src/crypto-providers/ledgerCryptoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
} from './types'
import {
findSigningPathForKeyHash,
PathTypes,
classifyPath,
getAddressAttributes,
ipv4ToString,
ipv6ToString,
Expand All @@ -47,6 +45,7 @@ import {
rewardAccountToStakeCredential,
areAddressParamsAllowed,
pathEquals,
isByronPath,
} from './util'

const { bech32 } = require('cardano-crypto.js')
Expand Down Expand Up @@ -576,8 +575,6 @@ export const LedgerCryptoProvider: (transport: Transport) => Promise<CryptoProvi
throw Error(Errors.MissingHwSigningDataAtPathError)
}

const isByronPath = (path: BIP32Path) => classifyPath(path) === PathTypes.PATH_WALLET_SPENDING_KEY_BYRON

const witnessesWithKeys = ledgerWitnesses.map((witness) => {
const { pubKey, chainCode } = splitXPubKeyCborHex(
getSigningFileDataByPath(witness.path as BIP32Path).cborXPubKeyHex,
Expand Down
3 changes: 3 additions & 0 deletions src/crypto-providers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ const pathEquals = (path1: BIP32Path, path2: BIP32Path) => (
path1.length === path2.length && path1.every((element, i) => element === path2[i])
)

const isByronPath = (path: BIP32Path) => classifyPath(path) === PathTypes.PATH_WALLET_SPENDING_KEY_BYRON
davidmisiak marked this conversation as resolved.
Show resolved Hide resolved

const splitXPubKeyCborHex = (xPubKeyCborHex: XPubKeyCborHex): _XPubKey => {
const xPubKeyDecoded = decodeCbor(xPubKeyCborHex)
const pubKey = xPubKeyDecoded.slice(0, 32)
Expand Down Expand Up @@ -557,6 +559,7 @@ export {
PathTypes,
classifyPath,
pathEquals,
isByronPath,
splitXPubKeyCborHex,
validateKeyGenInputs,
filterSigningFiles,
Expand Down
29 changes: 15 additions & 14 deletions src/fileWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
HARDENED_THRESHOLD,
PathLabel,
} from './constants'
import { classifyPath, PathTypes } from './crypto-providers/util'
import { classifyPath, isByronPath, PathTypes } from './crypto-providers/util'
import { OpCertIssueCounter, SignedOpCertCborHex } from './opCert/opCert'
import {
RawTxCborHex,
Expand Down Expand Up @@ -71,11 +71,12 @@ const constructBIP32PathOutput = (path: BIP32Path): string => path
.map((value) => (value >= HARDENED_THRESHOLD ? `${value - HARDENED_THRESHOLD}H` : `${value}`))
.join('/')

const bip32PathLabel = (path: number[]): PathLabel => {
const bip32PathLabel = (path: BIP32Path): PathLabel => {
switch (classifyPath(path)) {
case PathTypes.PATH_POOL_COLD_KEY:
return PathLabel.POOL_COLD

case PathTypes.PATH_WALLET_SPENDING_KEY_BYRON:
case PathTypes.PATH_WALLET_SPENDING_KEY_SHELLEY:
case PathTypes.PATH_WALLET_SPENDING_KEY_MULTISIG:
case PathTypes.PATH_WALLET_MINTING_KEY:
Expand All @@ -90,19 +91,14 @@ const bip32PathLabel = (path: number[]): PathLabel => {
}
}

const verificationKeyType = (path: number[]): string => {
const pathType = classifyPath(path)
const isShelleyEnvelope = pathType === PathTypes.PATH_WALLET_ACCOUNT
|| pathType === PathTypes.PATH_WALLET_SPENDING_KEY_SHELLEY
|| pathType === PathTypes.PATH_WALLET_STAKING_KEY
|| pathType === PathTypes.PATH_WALLET_ACCOUNT_MULTISIG
|| pathType === PathTypes.PATH_WALLET_SPENDING_KEY_MULTISIG
|| pathType === PathTypes.PATH_WALLET_STAKING_KEY_MULTISIG
|| pathType === PathTypes.PATH_WALLET_MINTING_KEY
return `${bip32PathLabel(path)}VerificationKey${isShelleyEnvelope ? 'Shelley' : ''}_ed25519`
const verificationKeyType = (path: BIP32Path): string => {
const label = bip32PathLabel(path)
return isByronPath(path)
? `${label}VerificationKeyByron_ed25519_bip32`
: `${label}VerificationKeyShelley_ed25519`
}

const verificationKeyDescription = (path: number[]): string => {
const verificationKeyDescription = (path: BIP32Path): string => {
switch (classifyPath(path)) {
case PathTypes.PATH_POOL_COLD_KEY:
return 'Stake Pool Operator Verification Key'
Expand All @@ -123,6 +119,8 @@ const verificationKeyDescription = (path: number[]): string => {
return 'Mint Verification Key'

case PathTypes.PATH_WALLET_SPENDING_KEY_BYRON:
return 'Payment Verification Key'

case PathTypes.PATH_WALLET_ACCOUNT:
case PathTypes.PATH_INVALID:
default:
Expand All @@ -144,8 +142,11 @@ const constructVerificationKeyOutput = (

const constructHwSigningKeyOutput = (xPubKey: XPubKeyHex, path: BIP32Path): HwSigningOutput => {
const label = bip32PathLabel(path)
const type = isByronPath(path)
? `${label}HWSigningFileByron_ed25519_bip32`
: `${label}HWSigningFileShelley_ed25519`
return {
type: `${label}HWSigningFileShelley_ed25519`,
type,
description: `${label} Hardware Signing File`,
path: constructBIP32PathOutput(path),
cborXPubKeyHex: encodeCbor(Buffer.from(xPubKey, 'hex')).toString('hex'),
Expand Down