Skip to content

Commit 8a046c7

Browse files
authored
Merge pull request #279 from EdgeApp/sam/rug-bip84
Disable bech32/bip84 wallet types
2 parents fb6d2b5 + b0eb133 commit 8a046c7

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

src/common/utxobased/engine/makeUtxoEngine.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,13 @@ export async function makeUtxoEngine(
5858
const asMaybeCurrencyPrivateKey = asMaybe(asCurrencyPrivateKey)
5959
// This walletInfo is desensitized (numb) and should be passed around over the original walletInfo
6060
const walletInfo = asNumbWalletInfo(pluginInfo)(sensitiveWalletInfo)
61-
const {
62-
publicKey,
63-
supportedFormats: walletFormatsSupported,
64-
format: walletFormat
65-
} = walletInfo.keys
61+
const { primaryFormat, publicKey, walletFormats } = walletInfo.keys
6662

6763
if (
6864
engineInfo.formats == null ||
69-
!engineInfo.formats.includes(walletFormat)
65+
!engineInfo.formats.includes(primaryFormat)
7066
) {
71-
const message = `Wallet format is not supported: ${walletFormat}`
67+
const message = `Wallet format is not supported: ${primaryFormat}`
7268
log.error(message)
7369
throw new Error(message)
7470
}
@@ -172,9 +168,9 @@ export async function makeUtxoEngine(
172168
walletType: walletInfo.type,
173169
data: {
174170
walletInfo: {
175-
walletFormat,
176-
walletFormatsSupported,
177-
pluginType: currencyInfo.pluginId
171+
pluginType: currencyInfo.pluginId,
172+
primaryFormat,
173+
walletFormats
178174
},
179175
processorState: await processor.dumpData(),
180176
pluginState: pluginState.dumpData()
@@ -536,8 +532,8 @@ export async function makeUtxoEngine(
536532
id: walletInfo.id,
537533
type: walletInfo.type,
538534
keys: {
539-
format: walletInfo.keys.format,
540-
supportedFormats: allFormats,
535+
primaryFormat: walletInfo.keys.primaryFormat,
536+
walletFormats: allFormats,
541537
publicKey: {
542538
publicKeys: {}
543539
}

src/common/utxobased/engine/makeUtxoEngineState.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function makeUtxoEngineState(
9595
pluginState
9696
} = config
9797

98-
const { supportedFormats } = walletInfo.keys
98+
const { walletFormats } = walletInfo.keys
9999

100100
const taskCache: TaskCache = {
101101
addressWatching: false,
@@ -169,7 +169,7 @@ export function makeUtxoEngineState(
169169
io: config.io,
170170
log,
171171
serverStates,
172-
supportedFormats,
172+
walletFormats,
173173
lock
174174
}
175175

@@ -235,7 +235,7 @@ export function makeUtxoEngineState(
235235
// processed by the processor. This happens only once before any call to
236236
// setLookAhead.
237237
const initializeAddressSubscriptions = async (): Promise<void> => {
238-
for (const format of supportedFormats) {
238+
for (const format of walletFormats) {
239239
const branches = getFormatSupportedBranches(format)
240240
for (const branch of branches) {
241241
const addressesToSubscribe = new Set<string>()
@@ -292,7 +292,9 @@ export function makeUtxoEngineState(
292292
},
293293

294294
async getFreshAddress(branch = 0): Promise<EdgeFreshAddress> {
295-
const walletPurpose = currencyFormatToPurposeType(walletInfo.keys.format)
295+
const walletPurpose = currencyFormatToPurposeType(
296+
walletInfo.keys.primaryFormat
297+
)
296298
if (walletPurpose === BIP43PurposeTypeEnum.Segwit) {
297299
const { address: publicAddress } = await internalGetFreshAddress({
298300
...commonArgs,
@@ -341,7 +343,7 @@ export function makeUtxoEngineState(
341343
engineInfo: commonArgs.pluginInfo.engineInfo,
342344
processor: commonArgs.processor,
343345
taskCache: commonArgs.taskCache,
344-
format: walletInfo.keys.format,
346+
format: walletInfo.keys.primaryFormat,
345347
script
346348
})
347349
return {
@@ -401,7 +403,7 @@ export function makeUtxoEngineState(
401403

402404
async loadWifs(wifs: string[]) {
403405
for (const wif of wifs) {
404-
for (const format of supportedFormats) {
406+
for (const format of walletFormats) {
405407
const changePath: ChangePath = {
406408
format,
407409
changeIndex: 0
@@ -446,7 +448,7 @@ interface CommonArgs {
446448
io: EdgeIo
447449
log: EdgeLog
448450
serverStates: ServerStates
449-
supportedFormats: CurrencyFormat[]
451+
walletFormats: CurrencyFormat[]
450452
lock: AwaitLock
451453
}
452454

@@ -502,7 +504,7 @@ const setLookAhead = async (common: CommonArgs): Promise<void> => {
502504
pluginInfo: { engineInfo },
503505
lock,
504506
processor,
505-
supportedFormats,
507+
walletFormats,
506508
walletTools
507509
} = common
508510

@@ -511,7 +513,7 @@ const setLookAhead = async (common: CommonArgs): Promise<void> => {
511513
await lock.acquireAsync()
512514

513515
try {
514-
for (const format of supportedFormats) {
516+
for (const format of walletFormats) {
515517
const branches = getFormatSupportedBranches(format)
516518
for (const branch of branches) {
517519
await deriveKeys({ format, changeIndex: branch })

src/common/utxobased/keymanager/cleaners.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export const getSupportedFormats = (
9191
case 'bip44':
9292
return ['bip44']
9393
case 'bip49':
94-
return ['bip49', 'bip84']
94+
return ['bip49']
9595
case 'bip84':
96-
return ['bip49', 'bip84']
96+
return ['bip84']
9797
default:
9898
throw new Error(`Unsupported format ${format}`)
9999
}
@@ -102,17 +102,23 @@ export const getSupportedFormats = (
102102
/**
103103
* A cleaner that desensitizes the walletInfo object, excluding sensitive
104104
* keys (seed/mnemonic, sync key, data key, etc). By using this object type
105-
* internally within the plugin, we can minimize risk.
105+
* internally within the plugin, we can minimize risk of leaking sensitive data.
106106
*
107-
* It also includes internal derived data (publicKey, format, supportedFormats, etc).
107+
* It also includes internal derived data (publicKey, format, walletFormats, etc).
108108
* This derived data is to be used internally within the plugin and saved to disk (publicKey).
109+
*
110+
* The `walletFormats` field is a list of formats from which to derive
111+
* extended-keys for the wallet.
112+
*
113+
* The `primaryFormat` field is the default format from which to derive
114+
* addresses from.
109115
*/
110116
export interface NumbWalletInfo {
111117
id: string
112118
type: string
113119
keys: {
114-
format: CurrencyFormat
115-
supportedFormats: CurrencyFormat[]
120+
primaryFormat: CurrencyFormat
121+
walletFormats: CurrencyFormat[]
116122
publicKey: PublicKey
117123
}
118124
}
@@ -127,7 +133,7 @@ export const asNumbWalletInfo = (
127133

128134
const publicKey = asMaybe(asPublicKey)(walletInfo.keys)
129135
if (publicKey != null) {
130-
const formats = Object.entries(publicKey.publicKeys)
136+
const walletFormats = Object.entries(publicKey.publicKeys)
131137
// Filter out undefined values in the entries because cleaners allow
132138
// undefined values for optional fields.
133139
.filter(([, value]) => value != null)
@@ -138,26 +144,26 @@ export const asNumbWalletInfo = (
138144
(format?: CurrencyFormat): format is CurrencyFormat => format != null
139145
)
140146

141-
if (formats.length === 0) {
147+
if (walletFormats.length === 0) {
142148
throw new Error('Missing wallet public keys')
143149
}
144150

145151
// Search the engineInfo's formats array for the first format that exists
146152
// in the publicKey data.
147-
// If there is not defined formats in the engineInfo, fallback to the first
148-
// format in the publicKey after sorting alphabetically.
149-
const format =
153+
// If there are no defined formats in the engineInfo, then fallback to the
154+
// first format in the publicKey after sorting alphabetically.
155+
const primaryFormat =
150156
(engineInfo.formats != null && engineInfo.formats.length > 0
151-
? engineInfo.formats.find(format => formats.includes(format))
157+
? engineInfo.formats.find(format => walletFormats.includes(format))
152158
: undefined) ??
153-
formats.sort((a, b) => (a === b ? 0 : a > b ? 1 : -1))[0]
159+
walletFormats.sort((a, b) => (a === b ? 0 : a > b ? 1 : -1))[0]
154160

155161
return {
156162
id,
157163
type,
158164
keys: {
159-
format,
160-
supportedFormats: formats,
165+
primaryFormat,
166+
walletFormats,
161167
publicKey
162168
}
163169
}
@@ -169,13 +175,14 @@ export const asNumbWalletInfo = (
169175
privateKey,
170176
coin: coinInfo.name
171177
})
178+
const walletFormats = getSupportedFormats(privateKey.format)
172179

173180
return {
174181
id,
175182
type,
176183
keys: {
177-
format: privateKey.format,
178-
supportedFormats: getSupportedFormats(privateKey.format),
184+
primaryFormat: privateKey.format,
185+
walletFormats,
179186
publicKey: { publicKeys: publicKey }
180187
}
181188
}

test/common/utxobased/engine/engine.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ for (const fixture of fixtures) {
462462
assert(dataDump.walletId === id, 'walletId')
463463
assert(dataDump.walletType === WALLET_TYPE, 'walletType')
464464
assert(
465-
dataDump.data.walletInfo.walletFormat === WALLET_FORMAT,
465+
dataDump.data.walletInfo.primaryFormat === WALLET_FORMAT,
466466
'walletFormat'
467467
)
468468
})

0 commit comments

Comments
 (0)