@@ -10,6 +10,7 @@ import (
10
10
"github.com/btcsuite/btcd/chaincfg"
11
11
"github.com/btcsuite/btcd/txscript"
12
12
"github.com/btcsuite/btcd/wire"
13
+ "github.com/decred/dcrd/dcrec/secp256k1/v4"
13
14
"github.com/lightninglabs/taproot-assets/asset"
14
15
"github.com/lightninglabs/taproot-assets/commitment"
15
16
"github.com/lightninglabs/taproot-assets/fn"
@@ -477,6 +478,64 @@ func TestBIPTestVectors(t *testing.T) {
477
478
}
478
479
}
479
480
481
+ // TestGenChallengeNUMS tests the generation of NUMS challenges.
482
+ func TestGenChallengeNUMS (t * testing.T ) {
483
+ t .Parallel ()
484
+
485
+ gx , gy := secp256k1 .Params ().Gx , secp256k1 .Params ().Gy
486
+
487
+ // addG is a helper function that adds G to the given public key.
488
+ addG := func (p * btcec.PublicKey ) * btcec.PublicKey {
489
+ x , y := secp256k1 .S256 ().Add (p .X (), p .Y (), gx , gy )
490
+ var xFieldVal , yFieldVal secp256k1.FieldVal
491
+ xFieldVal .SetByteSlice (x .Bytes ())
492
+ yFieldVal .SetByteSlice (y .Bytes ())
493
+ return btcec .NewPublicKey (& xFieldVal , & yFieldVal )
494
+ }
495
+
496
+ testCases := []struct {
497
+ name string
498
+ challenge fn.Option [[32 ]byte ]
499
+ expectedKey asset.ScriptKey
500
+ }{
501
+ {
502
+ name : "no challenge" ,
503
+ challenge : fn .None [[32 ]byte ](),
504
+ expectedKey : asset .NUMSScriptKey ,
505
+ },
506
+ {
507
+ name : "challenge is scalar 1" ,
508
+ challenge : fn .Some ([32 ]byte {
509
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
510
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
511
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
512
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 ,
513
+ }),
514
+ expectedKey : asset .NewScriptKey (addG (asset .NUMSPubKey )),
515
+ },
516
+ {
517
+ name : "challenge is scalar 2" ,
518
+ challenge : fn .Some ([32 ]byte {
519
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
520
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
521
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
522
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
523
+ }),
524
+ expectedKey : asset .NewScriptKey (
525
+ addG (addG (asset .NUMSPubKey )),
526
+ ),
527
+ },
528
+ }
529
+
530
+ for _ , tc := range testCases {
531
+ result := GenChallengeNUMS (tc .challenge )
532
+ require .Equal (
533
+ t , tc .expectedKey .PubKey .SerializeCompressed (),
534
+ result .PubKey .SerializeCompressed (),
535
+ )
536
+ }
537
+ }
538
+
480
539
// runBIPTestVector runs the tests in a single BIP test vector file.
481
540
func runBIPTestVector (t * testing.T , testVectors * TestVectors ) {
482
541
for _ , validCase := range testVectors .ValidTestCases {
0 commit comments