mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
[SDK] Fix tx history & Update WASM (#353)
* bugfix on detecting pending vtxos * bugfix: don't return on error from previous round * bugfix on wasm browser storage * implements listVtxos on SDK * Bug fix Co-authored-by: Pietralberto Mazza <altafan@users.noreply.github.com> * bug fix * Fixes * revert RedeemTx check * Fix after merge * bug fix on wasm wrapper * Fix static tx history (without tx feed) * add createAt timestamp in Vtxo domain * Fixes * Fixes * Polish * Fix * Fix --------- Co-authored-by: Pietralberto Mazza <altafan@users.noreply.github.com> Co-authored-by: altafan <18440657+altafan@users.noreply.github.com> Co-authored-by: louisinger <louis@vulpem.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
@@ -20,7 +19,7 @@ import (
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/vulpemventures/go-elements/address"
|
||||
"github.com/vulpemventures/go-elements/network"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
)
|
||||
|
||||
func CoinSelect(
|
||||
@@ -37,11 +36,7 @@ func CoinSelect(
|
||||
if sortByExpirationTime {
|
||||
// sort vtxos by expiration (older first)
|
||||
sort.SliceStable(vtxos, func(i, j int) bool {
|
||||
if vtxos[i].ExpiresAt == nil || vtxos[j].ExpiresAt == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return vtxos[i].ExpiresAt.Before(*vtxos[j].ExpiresAt)
|
||||
return vtxos[i].ExpiresAt.Before(vtxos[j].ExpiresAt)
|
||||
})
|
||||
|
||||
sort.SliceStable(boardingUtxos, func(i, j int) bool {
|
||||
@@ -190,12 +185,7 @@ func HashPassword(password []byte) []byte {
|
||||
return hash[:]
|
||||
}
|
||||
|
||||
func EncryptAES128(privateKey, password []byte) ([]byte, error) {
|
||||
// Due to https://github.com/golang/go/issues/7168.
|
||||
// This call makes sure that memory is freed in case the GC doesn't do that
|
||||
// right after the encryption/decryption.
|
||||
defer debug.FreeOSMemory()
|
||||
|
||||
func EncryptAES256(privateKey, password []byte) ([]byte, error) {
|
||||
if len(privateKey) == 0 {
|
||||
return nil, fmt.Errorf("missing plaintext private key")
|
||||
}
|
||||
@@ -227,9 +217,7 @@ func EncryptAES128(privateKey, password []byte) ([]byte, error) {
|
||||
return ciphertext, nil
|
||||
}
|
||||
|
||||
func DecryptAES128(encrypted, password []byte) ([]byte, error) {
|
||||
defer debug.FreeOSMemory()
|
||||
|
||||
func DecryptAES256(encrypted, password []byte) ([]byte, error) {
|
||||
if len(encrypted) == 0 {
|
||||
return nil, fmt.Errorf("missing encrypted mnemonic")
|
||||
}
|
||||
@@ -275,12 +263,8 @@ func deriveKey(password, salt []byte) ([]byte, []byte, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
// 2^20 = 1048576 recommended length for key-stretching
|
||||
// check the doc for other recommended values:
|
||||
// https://godoc.org/golang.org/x/crypto/scrypt
|
||||
key, err := scrypt.Key(password, salt, 1048576, 8, 1, 32)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
iterations := 10000
|
||||
keySize := 32
|
||||
key := pbkdf2.Key(password, salt, iterations, keySize, sha256.New)
|
||||
return key, salt, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user