File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,26 @@ def sign(key, tx_hash)
6161 )
6262 end
6363
64+ # @param index [Integer]
65+ # @param key [CKB::Key]
66+ #
67+ # @return [CKBP::Types::Transaction]
68+ def sign_input ( index , key )
69+ @hash = @hash || compute_hash
70+
71+ witness = witnesses [ index ] || ""
72+
73+ blake2b = CKB ::Blake2b . new
74+ blake2b . update ( Utils . hex_to_bin ( @hash ) )
75+ blake2b . update ( Utils . hex_to_bin ( witness ) )
76+ message = blake2b . hexdigest
77+ signed_witness = key . sign_recoverable ( message ) + witness [ 2 ..-1 ]
78+
79+ witnesses [ index ] = signed_witness
80+
81+ self
82+ end
83+
6484 def to_h
6585 hash = {
6686 version : Utils . to_hex ( @version ) ,
Original file line number Diff line number Diff line change 6363 expect ( signed_tx . to_h [ :witnesses ] ) . to eq ( [ "0x15edb4da91bd5beebf0aee82a9daa4d590ecdfc0895c6b010638573b2d1d502c50373e7d540e74eb8e3a3bd1dbd20c372c492fc7242592c8a04763be029325a900" ] )
6464 end
6565
66+ it "sign input" do
67+ tx_to_sign = CKB ::Types ::Transaction . from_h ( tx_to_sign_hash )
68+ key = CKB ::Key . new ( "0x845b781a1a094057b972714a2b09b85de4fc2eb205351c3e5179aabd264f3805" )
69+ tx_hash = "0x993e6e629be2f016bf72becaa9ad4b39f7fdd72357c9341335783f451010b94e"
70+ signed_tx = tx_to_sign . sign_input ( 0 , key )
71+
72+ expect ( signed_tx . to_h [ :hash ] ) . to eq ( tx_hash )
73+ expect ( signed_tx . to_h [ :witnesses ] ) . to eq ( [ "0xf198c795adfc5aead05ad0ac9d979519b0a707e7987c5addb3a6be42669af7f86e3a76a3ce8c770a92915e2d5a0212b3417db1c2152f2107ee7683601a4ecb5001" ] )
74+ end
75+
6676 context "multiple inputs sign" do
6777 let ( :tx_to_sign_hash ) do
6878 { version : "0x0" ,
You can’t perform that action at this time.
0 commit comments