This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multi-signing signature verification.
* Add multi-signing signature verification function. * Move `ignoreSigningFields` check on top level to fix the incorrect encoding of the empty ST_ARRAY.
- Loading branch information
1 parent
7f73b1f
commit cb4bf49
Showing
6 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package data | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/rubblelabs/ripple/crypto" | ||
) | ||
|
||
func TestMultiSignWithVerification(t *testing.T) { | ||
// generate signers seeds | ||
seed1 := genSeedFromPassword(t, "password1") | ||
seed2 := genSeedFromPassword(t, "password2") | ||
seq := uint32(0) | ||
key1 := seed1.Key(ECDSA) | ||
account1 := seed1.AccountId(ECDSA, &seq) | ||
key2 := seed2.Key(ECDSA) | ||
account2 := seed2.AccountId(ECDSA, &seq) | ||
|
||
// prepare first signature | ||
tx := buildPaymentTxForTheMultiSigning(t) | ||
if err := MultiSign(tx, key1, &seq, account1); err != nil { | ||
t.Fatal(err) | ||
} | ||
signer1 := Signer{ | ||
Signer: SignerItem{ | ||
Account: account1, | ||
TxnSignature: tx.TxnSignature, | ||
SigningPubKey: tx.SigningPubKey, | ||
}, | ||
} | ||
// prepare second signature | ||
tx = buildPaymentTxForTheMultiSigning(t) | ||
if err := MultiSign(tx, key2, &seq, account2); err != nil { | ||
t.Fatal(err) | ||
} | ||
signer2 := Signer{ | ||
Signer: SignerItem{ | ||
Account: account2, | ||
TxnSignature: tx.TxnSignature, | ||
SigningPubKey: tx.SigningPubKey, | ||
}, | ||
} | ||
// rebuild the tx and set signers | ||
tx = buildPaymentTxForTheMultiSigning(t) | ||
if err := SetSigners(tx, signer1, signer2); err != nil { | ||
t.Fatal(err) | ||
} | ||
// check that signature is valid | ||
valid, invalidSigners, err := CheckMultiSignature(tx) | ||
if !valid { | ||
t.Fatal(err) | ||
} | ||
if len(invalidSigners) != 0 { | ||
t.Fatal(err) | ||
} | ||
|
||
// update one signature | ||
tx.Signers[0].Signer.TxnSignature = tx.Signers[1].Signer.TxnSignature | ||
valid, invalidSigners, err = CheckMultiSignature(tx) | ||
if valid { | ||
t.Fatal(err) | ||
} | ||
if len(invalidSigners) != 1 { | ||
t.Fatal(err) | ||
} | ||
if !reflect.DeepEqual(invalidSigners[0], tx.Signers[0]) { | ||
t.Fatal(err) | ||
} | ||
|
||
// update tx data to check that both signers are invalid now | ||
tx.Sequence = 123 | ||
valid, invalidSigners, err = CheckMultiSignature(tx) | ||
if valid { | ||
t.Fatal(err) | ||
} | ||
if len(invalidSigners) != 2 { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func buildPaymentTxForTheMultiSigning(t *testing.T) *Payment { | ||
amount, err := NewAmount("1") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tx := Payment{ | ||
Amount: *amount, | ||
TxBase: TxBase{ | ||
Account: zeroAccount, | ||
Sequence: 1, | ||
TransactionType: PAYMENT, | ||
}, | ||
} | ||
// important for the multi-signing | ||
tx.TxBase.SigningPubKey = &PublicKey{} | ||
return &tx | ||
} | ||
|
||
func genSeedFromPassword(t *testing.T, password string) *Seed { | ||
seedFromPass, err := crypto.GenerateFamilySeed(password) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
seed, err := NewSeedFromAddress(seedFromPass.String()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return seed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters