Skip to content

Commit

Permalink
Release v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
slezica committed Mar 17, 2021
1 parent 893ea4f commit c082fdc
Show file tree
Hide file tree
Showing 67 changed files with 1,198 additions and 355 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified V1.go
100644 → 100755
Empty file.
Empty file modified V2.go
100644 → 100755
Empty file.
Empty file modified V3.go
100644 → 100755
Empty file.
Empty file modified V4.go
100644 → 100755
Empty file.
Empty file modified address.go
100644 → 100755
Empty file.
Empty file modified address_test.go
100644 → 100755
Empty file.
Empty file modified addresses/v2_test.go
100644 → 100755
Empty file.
Empty file modified addresses/v3_test.go
100644 → 100755
Empty file.
Empty file modified addresses/v4_test.go
100644 → 100755
Empty file.
Empty file modified aescbc/aescbc.go
100644 → 100755
Empty file.
Empty file modified bip70.proto
100644 → 100755
Empty file.
63 changes: 54 additions & 9 deletions challenge_keys.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ type encryptedPrivateKey struct {
Salt []byte // (optional) 8-byte salt
}

// EncryptedPrivateKeyInfo is a Gomobile-compatible version of EncryptedPrivateKey using hex-encoding.
type EncryptedPrivateKeyInfo struct {
Version int
Birthday int
EphPublicKey string
CipherText string
Salt string
}

type DecryptedPrivateKey struct {
Key *HDPrivateKey
Birthday int
Expand Down Expand Up @@ -69,8 +78,17 @@ func (k *ChallengePrivateKey) PubKey() *ChallengePublicKey {
return &ChallengePublicKey{pubKey: k.key.PubKey()}
}

func (k *ChallengePrivateKey) DecryptKey(encryptedKey string, network *Network) (*DecryptedPrivateKey, error) {
decoded, err := decodeEncryptedPrivateKey(encryptedKey)
func (k *ChallengePrivateKey) DecryptRawKey(encryptedKey string, network *Network) (*DecryptedPrivateKey, error) {
decoded, err := DecodeEncryptedPrivateKey(encryptedKey)
if err != nil {
return nil, err
}

return k.DecryptKey(decoded, network)
}

func (k *ChallengePrivateKey) DecryptKey(decodedInfo *EncryptedPrivateKeyInfo, network *Network) (*DecryptedPrivateKey, error) {
decoded, err := unwrapEncryptedPrivateKey(decodedInfo)
if err != nil {
return nil, err
}
Expand All @@ -94,7 +112,7 @@ func (k *ChallengePrivateKey) DecryptKey(encryptedKey string, network *Network)
}, nil
}

func decodeEncryptedPrivateKey(encodedKey string) (*encryptedPrivateKey, error) {
func DecodeEncryptedPrivateKey(encodedKey string) (*EncryptedPrivateKeyInfo, error) {
reader := bytes.NewReader(base58.Decode(encodedKey))
version, err := reader.ReadByte()
if err != nil {
Expand Down Expand Up @@ -136,12 +154,12 @@ func decodeEncryptedPrivateKey(encodedKey string) (*encryptedPrivateKey, error)
}
}

result := &encryptedPrivateKey{
Version: version,
Birthday: birthday,
EphPublicKey: rawPubEph,
CipherText: ciphertext,
Salt: recoveryCodeSalt,
result := &EncryptedPrivateKeyInfo{
Version: int(version),
Birthday: int(birthday),
EphPublicKey: hex.EncodeToString(rawPubEph),
CipherText: hex.EncodeToString(ciphertext),
Salt: hex.EncodeToString(recoveryCodeSalt),
}

return result, nil
Expand All @@ -150,3 +168,30 @@ func decodeEncryptedPrivateKey(encodedKey string) (*encryptedPrivateKey, error)
func shouldHaveSalt(encodedKey string) bool {
return len(encodedKey) > EncodedKeyLengthLegacy // not military-grade logic, but works for now
}

func unwrapEncryptedPrivateKey(info *EncryptedPrivateKeyInfo) (*encryptedPrivateKey, error) {
ephPublicKey, err := hex.DecodeString(info.EphPublicKey)
if err != nil {
return nil, err
}

cipherText, err := hex.DecodeString(info.CipherText)
if err != nil {
return nil, err
}

salt, err := hex.DecodeString(info.Salt)
if err != nil {
return nil, err
}

unwrapped := &encryptedPrivateKey{
Version: uint8(info.Version),
Birthday: uint16(info.Birthday),
EphPublicKey: ephPublicKey,
CipherText: cipherText,
Salt: salt,
}

return unwrapped, nil
}
38 changes: 13 additions & 25 deletions challenge_keys_test.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package libwallet

import (
"bytes"
"encoding/hex"
"reflect"
"testing"

Expand Down Expand Up @@ -57,7 +55,7 @@ func TestChallengeKeyCrypto(t *testing.T) {
t.Fatal(err)
}

decryptedKey, err := challengePrivKey.DecryptKey(encryptedKey, network)
decryptedKey, err := challengePrivKey.DecryptRawKey(encryptedKey, network)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -86,7 +84,7 @@ func TestChallengeKeyCryptoV2(t *testing.T) {
}

challengeKey := NewChallengePrivateKey([]byte(password), extractSalt(encryptedKey))
decryptedKey, err := challengeKey.DecryptKey(encryptedKey, Regtest())
decryptedKey, err := challengeKey.DecryptRawKey(encryptedKey, Regtest())
if err != nil {
t.Fatal(err)
}
Expand All @@ -112,34 +110,34 @@ func TestDecodeKeyWithOrWithoutSalt(t *testing.T) {
unsaltedKey = "5XEEts6mc9WV34krDWsqmpLcPCw2JkK8qJu3gFdZpP8ngkERuQEsaDvYrGkhXUpM6jQRtimTYm4XnBPujpo3MsdYBedsNVxvT3WC6uCCFuzNUZCoydVY39yJXbxva7naDxH5iTra"
)

expected := &encryptedPrivateKey{
expected := &EncryptedPrivateKeyInfo{
Version: 2,
Birthday: 376,
CipherText: unHex("f6af1ecd17052a81b75902c1712567cf1c650329875feb7e24af3e27235f384054ea549025e99dc2659f95bb6447cf861aa2ec0407ea74baf5a9d6a885ae184b"),
EphPublicKey: unHex("020a8d322dda8ff685d80b16681d4e87c109664cdc246a9d3625adfe0de203e71e"),
Salt: unHex("e3305526d0cd675f"),
CipherText: "f6af1ecd17052a81b75902c1712567cf1c650329875feb7e24af3e27235f384054ea549025e99dc2659f95bb6447cf861aa2ec0407ea74baf5a9d6a885ae184b",
EphPublicKey: "020a8d322dda8ff685d80b16681d4e87c109664cdc246a9d3625adfe0de203e71e",
Salt: "e3305526d0cd675f",
}

// Verify the salted version:
actual, err := decodeEncryptedPrivateKey(saltedKey)
actual, err := DecodeEncryptedPrivateKey(saltedKey)
if err != nil {
t.Fatal(err)
}

assertDecodedKeysEqual(t, actual, expected)

// Verify the unsalted version:
actual, err = decodeEncryptedPrivateKey(unsaltedKey)
actual, err = DecodeEncryptedPrivateKey(unsaltedKey)
if err != nil {
t.Fatal(err)
}

expected.Salt = make([]byte, 8) // unsalted key should decode with zeroed field
expected.Salt = "0000000000000000" // unsalted key should decode with zeroed field

assertDecodedKeysEqual(t, actual, expected)
}

func assertDecodedKeysEqual(t *testing.T, actual, expected *encryptedPrivateKey) {
func assertDecodedKeysEqual(t *testing.T, actual, expected *EncryptedPrivateKeyInfo) {
if actual.Version != expected.Version {
t.Fatalf("version %v expected %v", actual.Version, expected.Version)
}
Expand All @@ -148,25 +146,15 @@ func assertDecodedKeysEqual(t *testing.T, actual, expected *encryptedPrivateKey)
t.Fatalf("birthday %v, expected %v", actual.Birthday, expected.Birthday)
}

if !bytes.Equal(actual.CipherText, expected.CipherText) {
if actual.CipherText != expected.CipherText {
t.Fatalf("cipherText %x expected %x", actual.CipherText, expected.CipherText)
}

if !bytes.Equal(actual.EphPublicKey, expected.EphPublicKey) {
if actual.EphPublicKey != expected.EphPublicKey {
t.Fatalf("ephPublicKey %x expected %x", actual.EphPublicKey, expected.EphPublicKey)
}

if !bytes.Equal(actual.Salt, expected.Salt) {
if actual.Salt != expected.Salt {
t.Fatalf("salt %x expected %x", actual.Salt, expected.Salt)
}
}

// unHex decodes a string without returning an error (panic instead).
func unHex(text string) []byte {
data, err := hex.DecodeString(text)
if err != nil {
panic(err)
}

return data
}
Empty file modified challenge_public_key.go
100644 → 100755
Empty file.
13 changes: 6 additions & 7 deletions emergency_kit.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package libwallet

import (
"encoding/hex"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -96,12 +95,12 @@ func createEmergencyKitMetadata(ekParams *EKInput) (*emergencykit.Metadata, erro
// boundary to craft the object here.

// Decode both keys, to extract their inner properties:
firstKey, err := decodeEncryptedPrivateKey(ekParams.FirstEncryptedKey)
firstKey, err := DecodeEncryptedPrivateKey(ekParams.FirstEncryptedKey)
if err != nil {
return nil, fmt.Errorf("createEkMetadata failed to decode first key: %w", err)
}

secondKey, err := decodeEncryptedPrivateKey(ekParams.SecondEncryptedKey)
secondKey, err := DecodeEncryptedPrivateKey(ekParams.SecondEncryptedKey)
if err != nil {
return nil, fmt.Errorf("createEkMetadata failed to decode second key: %w", err)
}
Expand All @@ -128,10 +127,10 @@ func createEmergencyKitMetadata(ekParams *EKInput) (*emergencykit.Metadata, erro
return metadata, nil
}

func createEmergencyKitMetadataKey(key *encryptedPrivateKey) *emergencykit.MetadataKey {
func createEmergencyKitMetadataKey(key *EncryptedPrivateKeyInfo) *emergencykit.MetadataKey {
return &emergencykit.MetadataKey{
DhPubKey: hex.EncodeToString(key.EphPublicKey),
EncryptedPrivKey: hex.EncodeToString(key.CipherText),
Salt: hex.EncodeToString(key.Salt),
DhPubKey: key.EphPublicKey,
EncryptedPrivKey: key.CipherText,
Salt: key.Salt,
}
}
Empty file modified emergency_kit_test.go
100644 → 100755
Empty file.
Empty file modified encodings.go
100644 → 100755
Empty file.
Empty file modified encodings_test.go
100644 → 100755
Empty file.
Empty file modified encrypt.go
100644 → 100755
Empty file.
Empty file modified encrypt_test.go
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ require (
github.com/lightningnetwork/lightning-onion v1.0.1
github.com/lightningnetwork/lnd v0.10.4-beta
github.com/miekg/dns v1.1.29 // indirect
github.com/pdfcpu/pdfcpu v0.3.8
github.com/pdfcpu/pdfcpu v0.3.9
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/gormigrate.v1 v1.6.0
Expand Down
26 changes: 7 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e h1:F2x1bq7RaNCIuqYpswggh1+c1JmwdnkHNC9wy1KDip0=
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e/go.mod h1:BWqTsj8PgcPriQJGl7el20J/7TuT1d/hSyFDXMEpoEo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82 h1:MG93+PZYs9PyEsj/n5/haQu2gK0h4tUtSy9ejtMwWa0=
Expand Down Expand Up @@ -68,10 +67,6 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/champo/mobile v0.0.0-20201225234154-3393de95d3bb h1:Doj1b3qkFX5zakU7uJ1lpsER6GNS4R65Zbfrpz2fIWE=
github.com/champo/mobile v0.0.0-20201225234154-3393de95d3bb/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
github.com/champo/mobile v0.0.0-20201226003606-ef8e5756cda7 h1:jbaq2lXHNbmLj9Ab3upCbYSZ/j/TQ6yzDwie/pNyfqA=
github.com/champo/mobile v0.0.0-20201226003606-ef8e5756cda7/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -226,8 +221,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pdfcpu/pdfcpu v0.3.8 h1:wdKii186dzmr/aP/fkJl2s9yT3TZcwc1VqgfabNymGI=
github.com/pdfcpu/pdfcpu v0.3.8/go.mod h1:EfJ1EIo3n5+YlGF53DGe1yF1wQLiqK1eqGDN5LuKALs=
github.com/pdfcpu/pdfcpu v0.3.9 h1:gHPreswsOGwe1zViJxufbvNZf0xhK4mxj/r1CwLp958=
github.com/pdfcpu/pdfcpu v0.3.9/go.mod h1:EfJ1EIo3n5+YlGF53DGe1yF1wQLiqK1eqGDN5LuKALs=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -269,27 +264,20 @@ golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd h1:ePuNC7PZ6O5BzgPn9bZayERXBdfZjUYoXEf5BTfDfh8=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -312,6 +300,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -328,19 +317,15 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69 h1:yBHHx+XZqXJBm6Exke3N7V9gnlsyXxoCPEb1yVenjfk=
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -368,15 +353,18 @@ google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v1 v1.0.1/go.mod h1:3NjfXwocQRYAPTq4/fzX+CwUhPRcR/azYRhj8G+LqMo=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gormigrate.v1 v1.6.0 h1:XpYM6RHQPmzwY7Uyu+t+xxMXc86JYFJn4nEc9HzQjsI=
gopkg.in/gormigrate.v1 v1.6.0/go.mod h1:Lf00lQrHqfSYWiTtPcyQabsDdM6ejZaMgV0OU6JMSlw=
gopkg.in/macaroon-bakery.v2 v2.0.1/go.mod h1:B4/T17l+ZWGwxFSZQmlBwp25x+og7OkhETfr3S9MbIA=
gopkg.in/macaroon.v2 v2.0.0/go.mod h1:+I6LnTMkm/uV5ew/0nsulNjL16SK4+C8yDmRUzHR17I=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
Empty file modified hdprivatekey.go
100644 → 100755
Empty file.
Empty file modified hdprivatekey_test.go
100644 → 100755
Empty file.
Empty file modified hdpublickey.go
100644 → 100755
Empty file.
Empty file modified hdpublickey_test.go
100644 → 100755
Empty file.
Empty file modified invoice.go
100644 → 100755
Empty file.
Empty file modified invoice_test.go
100644 → 100755
Empty file.
Empty file modified keycrypt/keycrypt.go
100644 → 100755
Empty file.
Empty file modified keycrypt/keycrypt_test.go
100644 → 100755
Empty file.
Empty file modified keycrypter.go
100644 → 100755
Empty file.
Empty file modified keycrypter_test.go
100644 → 100755
Empty file.
Empty file modified network.go
100644 → 100755
Empty file.
Empty file modified network_test.go
100644 → 100755
Empty file.
Empty file modified partiallysignedtransaction.go
100644 → 100755
Empty file.
Empty file modified partiallysignedtransaction_test.go
100644 → 100755
Empty file.
Empty file modified publickey.go
100644 → 100755
Empty file.
Empty file modified ripemd160.go
100644 → 100755
Empty file.
Empty file modified ripemd160_test.go
100644 → 100755
Empty file.
Empty file modified scrypt.go
100644 → 100755
Empty file.
Empty file modified segwit.go
100644 → 100755
Empty file.
15 changes: 8 additions & 7 deletions sphinx/sphinx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ func Validate(
if err != nil {
return err
}

amountToForward := payload.ForwardingInfo().AmountToForward
if amount != 0 && amountToForward > amount {
return fmt.Errorf(
"sphinx payment amount does not match (%v != %v)", amount, amountToForward,
)
}

// Validate payment secret if it exists
if payload.MPP != nil {
paymentAddr := payload.MPP.PaymentAddr()
amountToForward := payload.ForwardingInfo().AmountToForward
total := payload.MultiPath().TotalMsat()

if !bytes.Equal(paymentAddr[:], paymentSecret) {
return errors.New("sphinx payment secret does not match")
}

if amount != 0 && amountToForward > amount {
return fmt.Errorf(
"sphinx payment amount does not match (%v != %v)", amount, amountToForward,
)
}

if amountToForward < total {
return fmt.Errorf("payment is multipart. forwarded amt = %v, total amt = %v", amountToForward, total)
}
Expand Down
Empty file modified submarineSwap.go
100644 → 100755
Empty file.
Empty file modified submarineSwapV1.go
100644 → 100755
Empty file.
Empty file modified submarineSwapV2.go
100644 → 100755
Empty file.
Empty file modified swaps/v1_test.go
100644 → 100755
Empty file.
Loading

0 comments on commit c082fdc

Please sign in to comment.