mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-13 04:50:11 +00:00

* Naive bip39 with address reuse * Avoid address reuse in libkaspawallet * Add wallet daemon * Use daemon everywhere * Add forceOverride * Make CreateUnsignedTransaction endpoint receive amount in sompis * Collect close UTXOs * Filter out non-spendable UTXOs from selectUTXOs * Use different paths for multisig and non multisig * Fix tests to use non zero path * Fix multisig cosigner index detection * Add comments * Fix dump_unencrypted_data.go according to bip39 and bip32 * Fix wrong derivation path for multisig on wallet creation * Remove IsSynced endpoint and add validation if wallet is synced for the relevant endpoints * Rename server address to daemon address * Fix capacity for extendedPublicKeys * Use ReadBytes instead of ReadLine * Add validation when importing * Increment before using index value, and use it as is * Save keys file exactly where needed * Use %+v printErrorAndExit * Remove redundant consts * Rnemae collectCloseUTXOs and collectFarUTXOs * Move typedefs around * Add comment to addressesToQuery * Update collectUTXOsFromRecentAddresses comment about locks * Split collectUTXOs to small functions * Add sanity check * Add addEntryToUTXOSet function * Change validateIsSynced to isSynced * Simplify createKeyPairsFromFunction logic * Rename .Sync() to .Save() * Fix typo * Create bip39BitSize const * Add consts to purposes * Add multisig check for 'send' * Rename updatedPSTxBytes to partiallySignedTransaction * Change collectUTXOsFromFarAddresses's comment * Use setters for last used indexes * Don't use the pstx acronym * Fix SetPath * Remove spaces when reading lines * Fix walletserver to daemonaddress * Fix isUTXOSpendable to use DAA score Co-authored-by: Svarog <feanorr@gmail.com>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet/bip32"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/utils"
|
|
"github.com/pkg/errors"
|
|
"os"
|
|
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
|
|
)
|
|
|
|
func create(conf *createConfig) error {
|
|
var encryptedMnemonics []*keys.EncryptedMnemonic
|
|
var signerExtendedPublicKeys []string
|
|
var err error
|
|
isMultisig := conf.NumPublicKeys > 1
|
|
if !conf.Import {
|
|
encryptedMnemonics, signerExtendedPublicKeys, err = keys.CreateMnemonics(conf.NetParams(), conf.NumPrivateKeys, isMultisig)
|
|
} else {
|
|
encryptedMnemonics, signerExtendedPublicKeys, err = keys.ImportMnemonics(conf.NetParams(), conf.NumPrivateKeys, isMultisig)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for i, extendedPublicKey := range signerExtendedPublicKeys {
|
|
fmt.Printf("Extended public key of mnemonic #%d:\n%s\n\n", i+1, extendedPublicKey)
|
|
}
|
|
|
|
extendedPublicKeys := make([]string, conf.NumPrivateKeys, conf.NumPublicKeys)
|
|
copy(extendedPublicKeys, signerExtendedPublicKeys)
|
|
reader := bufio.NewReader(os.Stdin)
|
|
for i := conf.NumPrivateKeys; i < conf.NumPublicKeys; i++ {
|
|
fmt.Printf("Enter public key #%d here:\n", i+1)
|
|
extendedPublicKey, err := utils.ReadLine(reader)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = bip32.DeserializeExtendedKey(string(extendedPublicKey))
|
|
if err != nil {
|
|
return errors.Wrapf(err, "%s is invalid extended public key", string(extendedPublicKey))
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
extendedPublicKeys = append(extendedPublicKeys, string(extendedPublicKey))
|
|
}
|
|
|
|
cosignerIndex, err := libkaspawallet.MinimumCosignerIndex(signerExtendedPublicKeys, extendedPublicKeys)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
file := keys.File{
|
|
EncryptedMnemonics: encryptedMnemonics,
|
|
ExtendedPublicKeys: extendedPublicKeys,
|
|
MinimumSignatures: conf.MinimumSignatures,
|
|
CosignerIndex: cosignerIndex,
|
|
ECDSA: conf.ECDSA,
|
|
}
|
|
|
|
err = file.SetPath(conf.NetParams(), conf.KeysFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = file.Save()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("Wrote the keys into %s\n", file.Path())
|
|
return nil
|
|
}
|