refactor: remove all use of cast in modules within nim_status
This commit is contained in:
parent
9e70dbc89a
commit
16045f5cee
|
@ -26,7 +26,7 @@ proc `$`*(acc: Account): string =
|
||||||
echo "Addr: ", acc.address
|
echo "Addr: ", acc.address
|
||||||
echo "PrivateKey: ", acc.privateKey
|
echo "PrivateKey: ", acc.privateKey
|
||||||
echo "PublicKey: ", acc.publicKey
|
echo "PublicKey: ", acc.publicKey
|
||||||
echo "Path: ", cast[string](acc.path)
|
echo "Path: ", acc.path.string
|
||||||
echo "Account end"
|
echo "Account end"
|
||||||
|
|
||||||
proc toDisplayString*(account: Account): string =
|
proc toDisplayString*(account: Account): string =
|
||||||
|
@ -38,7 +38,7 @@ proc getSeed*(mnemonic: Mnemonic, password: KeystorePass = ""): KeySeed =
|
||||||
KeySeed sha512.pbkdf2(mnemonic.string, salt, 2048, 64)
|
KeySeed sha512.pbkdf2(mnemonic.string, salt, 2048, 64)
|
||||||
|
|
||||||
proc splitHMAC*(seed: string, salt: string): ExtendedPrivKeyResult =
|
proc splitHMAC*(seed: string, salt: string): ExtendedPrivKeyResult =
|
||||||
let hmacResult = sha512.hmac(masterSecret, cast[seq[byte]](seed))
|
let hmacResult = sha512.hmac(masterSecret, seed.toBytes())
|
||||||
let secretKey = hmacResult.data[0..31]
|
let secretKey = hmacResult.data[0..31]
|
||||||
let chainCode = hmacResult.data[32..63]
|
let chainCode = hmacResult.data[32..63]
|
||||||
let sk = SkSecretKey.fromRaw(secretKey)
|
let sk = SkSecretKey.fromRaw(secretKey)
|
||||||
|
@ -78,7 +78,7 @@ proc child(self: ExtendedPrivKey, child: PathLevel): ExtendedPrivKeyResult =
|
||||||
err($sk.error())
|
err($sk.error())
|
||||||
|
|
||||||
proc derive*(seed: Keyseed, path: KeyPath): SecretKeyResult =
|
proc derive*(seed: Keyseed, path: KeyPath): SecretKeyResult =
|
||||||
var extPrivK = splitHMAC(cast[string](seed), masterSecret).get()
|
var extPrivK = splitHMAC(string.fromBytes(openArray[byte](seed)), masterSecret).get()
|
||||||
|
|
||||||
for child in path.pathNodes:
|
for child in path.pathNodes:
|
||||||
if child.isErr(): return err(child.error().cstring)
|
if child.isErr(): return err(child.error().cstring)
|
||||||
|
|
|
@ -167,6 +167,6 @@ proc blockContact*(db: DbConn, contact: Contact): seq[Chat] =
|
||||||
let encodedMessage = $$lastMessage
|
let encodedMessage = $$lastMessage
|
||||||
query = fmt"""UPDATE chats SET last_message = ? WHERE id = ?"""
|
query = fmt"""UPDATE chats SET last_message = ? WHERE id = ?"""
|
||||||
db.exec(query, encodedMessage, c.id)
|
db.exec(query, encodedMessage, c.id)
|
||||||
c.lastMessage = some(cast[seq[byte]](encodedMessage))
|
c.lastMessage = some(encodedMessage.toBytes())
|
||||||
|
|
||||||
chats
|
chats
|
||||||
|
|
|
@ -25,7 +25,7 @@ proc `$`*(s: BitSeq): string =
|
||||||
proc getBits*(b: byte): BitSeq =
|
proc getBits*(b: byte): BitSeq =
|
||||||
var s = newSeq[byte]()
|
var s = newSeq[byte]()
|
||||||
for i in 0..7:
|
for i in 0..7:
|
||||||
let bit = cast[byte]((b shr i) and 1)
|
let bit = (b shr i) and 1
|
||||||
s.insert(bit, 0)
|
s.insert(bit, 0)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -40,7 +40,7 @@ proc getBits*(byteSeq: seq[byte]): BitSeq =
|
||||||
proc getBits*(byteStr: string): BitSeq =
|
proc getBits*(byteStr: string): BitSeq =
|
||||||
var s: BitSeq
|
var s: BitSeq
|
||||||
for b in byteStr:
|
for b in byteStr:
|
||||||
let bits = getBits(cast[byte](b))
|
let bits = getBits(b.byte)
|
||||||
s = concat(s, bits)
|
s = concat(s, bits)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -86,4 +86,3 @@ proc mnemonicPhrase*(strength: int, language: Language): Mnemonic =
|
||||||
|
|
||||||
|
|
||||||
return Mnemonic words.join(wordSeparator)
|
return Mnemonic words.join(wordSeparator)
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ proc deriveAccounts*(multiAcc: MultiAccount, paths: seq[KeyPath]): seq[Account]
|
||||||
var accounts: seq[Account]
|
var accounts: seq[Account]
|
||||||
for p in paths:
|
for p in paths:
|
||||||
let skResult = derive(multiAcc.keySeed, p)
|
let skResult = derive(multiAcc.keySeed, p)
|
||||||
var acc = buildAccount(cast[PrivateKey](skResult.get()))
|
var acc = buildAccount(PrivateKey(skResult.get()))
|
||||||
acc.path = p
|
acc.path = p
|
||||||
accounts.add(acc)
|
accounts.add(acc)
|
||||||
return accounts
|
return accounts
|
||||||
|
@ -71,7 +71,7 @@ proc deriveAccounts*(multiAcc: MultiAccount, paths: seq[KeyPath]): seq[Account]
|
||||||
proc importMnemonic*(mnemonicPhrase: Mnemonic, bip39Passphrase: string): MultiAccount =
|
proc importMnemonic*(mnemonicPhrase: Mnemonic, bip39Passphrase: string): MultiAccount =
|
||||||
let seed = getSeed(Mnemonic mnemonicPhrase, bip39Passphrase)
|
let seed = getSeed(Mnemonic mnemonicPhrase, bip39Passphrase)
|
||||||
# Ensure seed is within expected limits
|
# Ensure seed is within expected limits
|
||||||
let lseed = len(cast[seq[byte]](seed))
|
let lseed = openArray[byte](seed).len
|
||||||
if lseed < MIN_SEED_BYTES or lseed > MAX_SEED_BYTES:
|
if lseed < MIN_SEED_BYTES or lseed > MAX_SEED_BYTES:
|
||||||
return MultiAccount()
|
return MultiAccount()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ procSuite "mnemonic":
|
||||||
|
|
||||||
echo "BitSeq: ", s
|
echo "BitSeq: ", s
|
||||||
|
|
||||||
let mnemonic = mnemonicPhrase(128, Language.English)
|
let mnemonic = mnemonicPhrase(128, Language.English).string
|
||||||
echo "phrase:"
|
echo "phrase:"
|
||||||
echo mnemonic
|
echo mnemonic
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue