Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
xxuejie committed Jun 3, 2019
1 parent a16ab01 commit 4be8ac8
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions lib/ckb/types/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ def sign(key, tx_hash)

signed_witnesses = witnesses.map do |witness|
old_data = witness.data || []
signature_hex_var = signature_hex(key, [tx_hash] + old_data)
data = [key.pubkey, signature_hex_var] + old_data
blake2b = CKB::Blake2b.new
blake2b.update(Utils.hex_to_bin(tx_hash))
data.each do |datum|
blake2b.update(Utils.hex_to_bin(datum))
end
message = Utils.bin_to_hex(blake2b.digest)
data = [key.pubkey, key.sign(message)] + old_data
Types::Witness.from_h(data: data)
end

Expand Down Expand Up @@ -73,21 +78,6 @@ def self.from_h(hash)
witnesses: hash[:witnesses].map { |witness| Witness.from_h(witness) }
)
end

private

def signature_hex(key, data)
blake2b = CKB::Blake2b.new
data.each do |datum|
blake2b.update(Utils.hex_to_bin(datum))
end
privkey_bin = Utils.hex_to_bin(key.privkey)
secp_key = Secp256k1::PrivateKey.new(privkey: privkey_bin)
signature_bin = secp_key.ecdsa_serialize(
secp_key.ecdsa_sign(blake2b.digest, raw: true)
)
Utils.bin_to_hex(signature_bin)
end
end
end
end

0 comments on commit 4be8ac8

Please sign in to comment.