Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('btcGetAccountPaths()', async () => {
await each([
['Bitcoin', 0, undefined],
['Bitcoin', 1, BTCInputScriptType.SpendAddress],
['Bitcoin', 3, BTCInputScriptType.SpendP2SHWitness],
['Bitcoin', 2, BTCInputScriptType.SpendWitness],
['Litecoin', 1, BTCInputScriptType.SpendAddress],
['Litecoin', 1, BTCInputScriptType.SpendP2SHWitness],
['Dash', 0, BTCInputScriptType.SpendAddress],
['Dogecoin', 0, BTCInputScriptType.SpendAddress],
['BitcoinCash', 0, BTCInputScriptType.SpendAddress],
['BitcoinGold', 0, BTCInputScriptType.SpendAddress],
], async (args) => {
let coin = args[0] as Coin
let accountIdx = args[1] as number
let scriptType = args[2] as BTCInputScriptType
if (!wallet) return
if (!await wallet.btcSupportsCoin(coin))
return
expect(await info.btcSupportsCoin(coin)).toBeTruthy()
if (!await wallet.btcSupportsScriptType(coin, scriptType))
return
if (purpose === 44 && scriptType !== BTCInputScriptType.SpendAddress)
return unknown
if (purpose === 49 && scriptType !== BTCInputScriptType.SpendP2SHWitness)
return unknown
if (purpose === 84 && scriptType !== BTCInputScriptType.SpendWitness)
return unknown
let wholeAccount = path.length === 3
let script = {
[BTCInputScriptType.SpendAddress]: ['Legacy'],
[BTCInputScriptType.SpendP2SHWitness]: [],
[BTCInputScriptType.SpendWitness]: ['Segwit Native']
}[scriptType]
let isPrefork = false
if (path[1] !== 0x80000000 + slip44ByCoin(coin)) {
switch (coin) {
case 'BitcoinCash':
case 'BitcoinGold': {
if (path[1] === 0x80000000 + slip44ByCoin('Bitcoin')) {
isPrefork = true
break
}
return unknown
}
case 'BitcoinSV': {
if (path[1] === 0x80000000 + slip44ByCoin('Bitcoin') ||
path[1] === 0x80000000 + slip44ByCoin('BitcoinCash')) {
export function translateInputScriptType (scriptType: BTCInputScriptType): any {
switch (scriptType) {
case BTCInputScriptType.CashAddr:
case BTCInputScriptType.SpendAddress:
return InputScriptType.SPENDADDRESS
case BTCInputScriptType.SpendMultisig:
return InputScriptType.SPENDMULTISIG
case BTCInputScriptType.SpendP2SHWitness:
return InputScriptType.SPENDP2SHWITNESS
case BTCInputScriptType.SpendWitness:
return InputScriptType.SPENDWITNESS
}
throw new Error('unhandled InputSriptType enum: ' + scriptType)
}
'coin': 'Litecoin',
}, {
"addressNList": [
2147483692,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendAddress,
'coin': 'Litecoin',
}, {
"addressNList": [
2147483732,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendWitness,
'coin': 'Litecoin',
}])
})
if (purpose === 49 && scriptType !== BTCInputScriptType.SpendP2SHWitness)
return unknown
if (purpose === 84 && scriptType !== BTCInputScriptType.SpendWitness)
return unknown
if (path[1] !== 0x80000000 + slip44ByCoin(coin))
return unknown
let wholeAccount = path.length === 3
let script = {
[BTCInputScriptType.SpendAddress]: ' (Legacy)',
[BTCInputScriptType.SpendP2SHWitness]: '',
[BTCInputScriptType.SpendWitness]: ' (Segwit Native)'
}[scriptType]
switch (coin) {
case 'Bitcoin':
case 'Litecoin':
case 'BitcoinGold':
case 'Testnet':
break;
default:
script = ''
}
let accountIdx = path[2] & 0x7fffffff
if (wholeAccount) {
return {
function segwitNativeAccount (coin: Coin, slip44: number, accountIdx: number): BTCAccountPath {
return {
coin,
scriptType: BTCInputScriptType.SpendWitness,
addressNList: [ 0x80000000 + 84, 0x80000000 + slip44, 0x80000000 + accountIdx ]
}
}
if ((path[0] & 0x80000000) >>> 0 !== 0x80000000)
return unknown
let purpose = path[0] & 0x7fffffff
if (![44, 49, 84].includes(purpose))
return unknown
if (purpose === 44 && scriptType !== BTCInputScriptType.SpendAddress)
return unknown
if (purpose === 49 && scriptType !== BTCInputScriptType.SpendP2SHWitness)
return unknown
if (purpose === 84 && scriptType !== BTCInputScriptType.SpendWitness)
return unknown
let wholeAccount = path.length === 3
let script = {
[BTCInputScriptType.SpendAddress]: ['Legacy'],
[BTCInputScriptType.SpendP2SHWitness]: [],
[BTCInputScriptType.SpendWitness]: ['Segwit Native']
}[scriptType]
let isPrefork = false
if (path[1] !== 0x80000000 + slip44ByCoin(coin)) {
switch (coin) {
case 'BitcoinCash':
case 'BitcoinGold': {
if (path[1] === 0x80000000 + slip44ByCoin('Bitcoin')) {
'coin': 'Litecoin',
}, {
"addressNList": [
2147483697,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendP2SHWitness,
'coin': 'Litecoin',
}, {
"addressNList": [
2147483732,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendWitness,
'coin': 'Litecoin',
}])
})
export async function btcSupportsScriptType (coin: Coin, scriptType: BTCInputScriptType): Promise {
if (translateCoin(coin) === undefined)
return false
if (!segwitCoins.includes(coin) && scriptType === BTCInputScriptType.SpendP2SHWitness)
return false
if (!segwitCoins.includes(coin) && scriptType === BTCInputScriptType.SpendWitness)
return false
return true
}
'coin': 'Litecoin',
}, {
"addressNList": [
2147483692,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendAddress,
'coin': 'Litecoin',
}, {
"addressNList": [
2147483732,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendWitness,
'coin': 'Litecoin',
}])
})