Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function verifyScriptTypePurpose(scriptType: BTCInputScriptType, purpose: number): boolean {
return (
(purpose === 0x80000000 + 44 && scriptType === BTCInputScriptType.SpendAddress ) ||
(purpose === 0x80000000 + 49 && scriptType === BTCInputScriptType.SpendP2SHWitness ) ||
(purpose === 0x80000000 + 84 && scriptType === BTCInputScriptType.SpendWitness )
)
}
function segwitAccount (coin: Coin, slip44: number, accountIdx: number): BTCAccountPath {
return {
coin,
scriptType: BTCInputScriptType.SpendP2SHWitness,
addressNList: [ 0x80000000 + 49, 0x80000000 + slip44, 0x80000000 + accountIdx ]
}
}
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')) {
isPrefork = true
break
}
return unknown
}
case 'BitcoinSV': {
if (path[1] === 0x80000000 + slip44ByCoin('Bitcoin') ||
export function btcGetAccountPaths (msg: BTCGetAccountPaths): Array {
const slip44 = slip44ByCoin(msg.coin)
const bip44 = {
coin: msg.coin,
scriptType: BTCInputScriptType.SpendAddress,
addressNList: [ 0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx ]
}
const bip49 = {
coin: msg.coin,
scriptType: BTCInputScriptType.SpendP2SHWitness,
addressNList: [ 0x80000000 + 49, 0x80000000 + slip44, 0x80000000 + msg.accountIdx ]
}
const bip84 = {
coin: msg.coin,
scriptType: BTCInputScriptType.SpendWitness,
addressNList: [ 0x80000000 + 84, 0x80000000 + slip44, 0x80000000 + msg.accountIdx ]
}
let paths: Array
if (segwitCoins.includes(msg.coin))
paths = [ bip49, bip44, bip84 ]
else
paths = [ bip44 ]
if (msg.scriptType !== undefined)
return res.payload.map((result, i) => {
const scriptType = msg[i].scriptType
switch (scriptType) {
case BTCInputScriptType.SpendP2SHWitness:
case BTCInputScriptType.SpendWitness:
return {
xpub: result.xpubSegwit
}
case BTCInputScriptType.SpendAddress:
default:
return {
xpub: result.xpub
}
}
})
}
export async function btcSupportsScriptType (coin: Coin, scriptType: BTCInputScriptType): Promise {
const supported = {
Bitcoin: [
BTCInputScriptType.SpendAddress,
BTCInputScriptType.SpendWitness,
BTCInputScriptType.SpendP2SHWitness
],
BitcoinCash: [
BTCInputScriptType.SpendAddress
]
}
return !!supported[coin] && supported[coin].includes(scriptType)
}
expect(paths).toEqual([{
"addressNList": [
2147483692,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendAddress,
'coin': 'Litecoin',
}, {
"addressNList": [
2147483697,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendP2SHWitness,
'coin': 'Litecoin',
}, {
"addressNList": [
2147483732,
2147483650,
2147483651,
],
"scriptType": BTCInputScriptType.SpendWitness,
'coin': 'Litecoin',
}])
})
export function segwitAccount (coin: Coin, slip44: number, accountIdx: number): BTCAccountPath {
return {
coin,
scriptType: BTCInputScriptType.SpendP2SHWitness,
addressNList: [ 0x80000000 + 49, 0x80000000 + slip44, 0x80000000 + accountIdx ]
}
}
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')) {
isPrefork = true
break
}
return unknown
}
case 'BitcoinSV': {
if (path[1] === 0x80000000 + slip44ByCoin('Bitcoin') ||