Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getAddresses (startingIndex = 0, numAddresses = 1, change = false) {
if (numAddresses < 1) { throw new Error('You must return at least one address') }
const node = await this.node()
const addresses = []
const lastIndex = startingIndex + numAddresses
const changeVal = change ? '1' : '0'
for (let currentIndex = startingIndex; currentIndex < lastIndex; currentIndex++) {
const subPath = changeVal + '/' + currentIndex
const path = this._derivationPath + subPath
const publicKey = node.derivePath(path).publicKey
const address = this.getAddressFromPublicKey(publicKey)
addresses.push(new Address({
address,
publicKey,
derivationPath: path,
index: currentIndex
}))
}
return addresses
}
async getAddresses () {
const derivationPath = this._derivationPath + '0/0'
const hdKey = await this.hdKey(derivationPath)
const address = ethUtil.privateToAddress(hdKey._privateKey).toString('hex')
const publicKey = ethUtil.privateToPublic(hdKey._privateKey).toString('hex')
return [
new Address({
address,
derivationPath,
publicKey,
index: 0
})
]
}
async getNewAddress (addressType, label = '') {
const params = addressType ? [label, addressType] : [label]
const newAddress = await this._rpc.jsonrpc('getnewaddress', ...params)
if (!newAddress) return null
return new Address(newAddress)
}
Buffer.from(compressedPubKey, 'hex'),
Buffer.from(walletPubKey.chainCode, 'hex'),
this._network
)
const addresses = []
const lastIndex = startingIndex + numAddresses
const changeVal = change ? '1' : '0'
for (let currentIndex = startingIndex; currentIndex < lastIndex; currentIndex++) {
const subPath = changeVal + '/' + currentIndex
const publicKey = node.derivePath(subPath).publicKey
const address = pubKeyToAddress(publicKey, this._network.name, 'pubKeyHash')
const path = this._baseDerivationPath + subPath
addresses.push(new Address({
address,
publicKey: publicKey.toString('hex'),
derivationPath: path,
index: currentIndex
}))
}
return addresses
}
async getAddresses (startingIndex = 0, numAddresses = 1, change = false) {
if (numAddresses < 1) { throw new Error('You must return at least one address') }
const node = await this.node()
const addresses = []
const lastIndex = startingIndex + numAddresses
const changeVal = change ? '1' : '0'
for (let currentIndex = startingIndex; currentIndex < lastIndex; currentIndex++) {
const subPath = changeVal + '/' + currentIndex
const path = this._derivationPath + subPath
const publicKey = node.derivePath(path).publicKey
const address = this.getAddressFromPublicKey(publicKey)
addresses.push(new Address({
address,
publicKey,
derivationPath: path,
index: currentIndex
}))
}
return addresses
}