Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _initKeyringByName (name) {
if (this._has3idProv) throw new Error('Can not initKeyringByName of IdentityWallet')
if (!this._keyrings[name]) {
const sig = await utils.openSpaceConsent(this.managementAddress, this._provider, name)
const entropy = '0x' + utils.sha256(sig.slice(2))
const seed = mnemonicToSeed(entropyToMnemonic(entropy))
this._keyrings[name] = new Keyring(seed)
this._subDIDs[name] = await this._init3ID(name)
localstorage.set(STORAGE_KEY + this.managementAddress, this.serializeState())
return true
} else {
return false
}
}
} else {
const normalizedAddress = address.toLowerCase()
let serialized3id = localstorage.get(STORAGE_KEY + normalizedAddress)
if (serialized3id) {
if (opts.consentCallback) opts.consentCallback(false)
} else {
let sig
if (opts.contentSignature) {
sig = opts.contentSignature
} else {
sig = await utils.openBoxConsent(normalizedAddress, provider)
}
if (opts.consentCallback) opts.consentCallback(true)
const entropy = '0x' + utils.sha256(sig.slice(2))
const mnemonic = entropyToMnemonic(entropy)
const seed = mnemonicToSeed(mnemonic)
serialized3id = JSON.stringify({
managementAddress: normalizedAddress,
seed,
spaceSeeds: {}
})
}
const threeId = new ThreeId(provider, ipfs, opts)
threeId._initKeys(serialized3id)
await threeId._initDID()
return threeId
}
}
}