Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor (seed) {
this._seed = seed
const seedNode = HDNode.fromSeed(this._seed)
const baseNode = seedNode.derivePath(BASE_PATH)
this.signingKey = baseNode.derivePath("0")
const tmpEncKey = Buffer.from(baseNode.derivePath("2").privateKey.slice(2), 'hex')
this.asymEncryptionKey = nacl.box.keyPair.fromSecretKey(new Uint8Array(tmpEncKey))
this.symEncryptionKey = new Uint8Array(Buffer.from(baseNode.derivePath("3").privateKey.slice(2), 'hex'))
this.ethereumKey = seedNode.derivePath(MM_PATH).derivePath("0")
}
static encryptWithAuthSecret (message, authSecret) {
const node = HDNode.fromSeed(ensure0x(authSecret)).derivePath(AUTH_PATH_ENCRYPTION)
const key = Keyring.hexToUint8Array(node.privateKey.slice(2))
return Keyring.symEncryptBase(message, key)
}
static walletForAuthSecret (authSecret) {
const node = HDNode.fromSeed(ensure0x(authSecret)).derivePath(AUTH_PATH_WALLET)
return new Wallet(node.privateKey)
}
constructor (seed) {
this._seed = seed
this._baseNode = HDNode.fromSeed(this._seed).derivePath(BASE_PATH)
const rootNode = this._baseNode.derivePath(ROOT_STORE_PATH)
this._rootKeys = {
signingKey: rootNode.derivePath('0'),
managementKey: rootNode.derivePath('1'),
asymEncryptionKey: nacl.box.keyPair.fromSecretKey(new Uint8Array(
Buffer.from(rootNode.derivePath('2').privateKey.slice(2), 'hex')
)),
symEncryptionKey: Keyring.hexToUint8Array(rootNode.derivePath('3').privateKey.slice(2))
}
this._spaceKeys = {}
}
static decryptWithAuthSecret (ciphertext, nonce, authSecret) {
const node = HDNode.fromSeed(ensure0x(authSecret)).derivePath(AUTH_PATH_ENCRYPTION)
const key = Keyring.hexToUint8Array(node.privateKey.slice(2))
return Keyring.symDecryptBase(ciphertext, key, nonce)
}