bsv-sdk 0.20.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +106 -0
- data/lib/bsv/mcp/tools/broadcast_p2pkh.rb +5 -3
- data/lib/bsv/network/protocols/arc.rb +4 -30
- data/lib/bsv/network/protocols/arcade.rb +163 -0
- data/lib/bsv/network/protocols/chaintracks.rb +27 -4
- data/lib/bsv/network/protocols/jungle_bus.rb +34 -0
- data/lib/bsv/network/protocols/woc_rest.rb +28 -1
- data/lib/bsv/network/protocols.rb +1 -0
- data/lib/bsv/network/providers/gorilla_pool.rb +18 -18
- data/lib/bsv/network/util.rb +44 -0
- data/lib/bsv/network.rb +1 -0
- data/lib/bsv/transaction/chain_tracker.rb +66 -13
- data/lib/bsv/transaction/chain_trackers.rb +0 -10
- data/lib/bsv/transaction/fee_models/live_policy.rb +10 -8
- data/lib/bsv/version.rb +1 -1
- data/lib/bsv/wallet/errors.rb +65 -21
- data/lib/bsv/wallet/proto_wallet/validators.rb +7 -49
- data/lib/bsv/wallet/proto_wallet.rb +14 -1
- data/lib/bsv/wallet/serializer/abort_action.rb +38 -0
- data/lib/bsv/wallet/serializer/acquire_certificate.rb +171 -0
- data/lib/bsv/wallet/serializer/certificate.rb +184 -0
- data/lib/bsv/wallet/serializer/common.rb +207 -0
- data/lib/bsv/wallet/serializer/create_action_args.rb +259 -0
- data/lib/bsv/wallet/serializer/create_action_result.rb +85 -0
- data/lib/bsv/wallet/serializer/create_hmac.rb +67 -0
- data/lib/bsv/wallet/serializer/create_signature.rb +90 -0
- data/lib/bsv/wallet/serializer/decrypt.rb +60 -0
- data/lib/bsv/wallet/serializer/discover_by_attributes.rb +61 -0
- data/lib/bsv/wallet/serializer/discover_by_identity_key.rb +49 -0
- data/lib/bsv/wallet/serializer/discover_certificates_result.rb +39 -0
- data/lib/bsv/wallet/serializer/encrypt.rb +60 -0
- data/lib/bsv/wallet/serializer/get_header_for_height.rb +71 -0
- data/lib/bsv/wallet/serializer/get_height.rb +46 -0
- data/lib/bsv/wallet/serializer/get_network.rb +65 -0
- data/lib/bsv/wallet/serializer/get_public_key.rb +86 -0
- data/lib/bsv/wallet/serializer/get_version.rb +44 -0
- data/lib/bsv/wallet/serializer/internalize_action.rb +151 -0
- data/lib/bsv/wallet/serializer/list_actions.rb +348 -0
- data/lib/bsv/wallet/serializer/list_certificates.rb +124 -0
- data/lib/bsv/wallet/serializer/list_outputs.rb +167 -0
- data/lib/bsv/wallet/serializer/prove_certificate.rb +146 -0
- data/lib/bsv/wallet/serializer/relinquish_certificate.rb +56 -0
- data/lib/bsv/wallet/serializer/relinquish_output.rb +44 -0
- data/lib/bsv/wallet/serializer/reveal_counterparty_key_linkage.rb +108 -0
- data/lib/bsv/wallet/serializer/reveal_specific_key_linkage.rb +116 -0
- data/lib/bsv/wallet/serializer/sign_action_args.rb +94 -0
- data/lib/bsv/wallet/serializer/sign_action_result.rb +49 -0
- data/lib/bsv/wallet/serializer/status.rb +85 -0
- data/lib/bsv/wallet/serializer/verify_hmac.rb +67 -0
- data/lib/bsv/wallet/serializer/verify_signature.rb +101 -0
- data/lib/bsv/wallet/serializer.rb +180 -0
- data/lib/bsv/wallet/substrates/http_wallet_json.rb +129 -0
- data/lib/bsv/wallet/substrates/http_wallet_wire.rb +99 -0
- data/lib/bsv/wallet/wallet_wire.rb +20 -0
- data/lib/bsv/wallet/wallet_wire_processor.rb +61 -0
- data/lib/bsv/wallet/wallet_wire_transceiver.rb +61 -0
- data/lib/bsv/wallet/wire/calls.rb +79 -0
- data/lib/bsv/wallet/wire/frame.rb +181 -0
- data/lib/bsv/wallet/wire/reader_writer.rb +402 -0
- data/lib/bsv/wallet/wire/validation.rb +213 -0
- data/lib/bsv/wallet/wire.rb +13 -0
- data/lib/bsv/wallet.rb +17 -0
- metadata +46 -2
- data/lib/bsv/transaction/chain_trackers/chaintracks.rb +0 -83
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 wire codec for the +reveal_specific_key_linkage+ call (call byte 10).
|
|
7
|
+
#
|
|
8
|
+
# Port of go-sdk/wallet/serializer/reveal_specific_key_linkage.go.
|
|
9
|
+
module RevealSpecificKeyLinkage
|
|
10
|
+
PUBKEY_SIZE = 33
|
|
11
|
+
|
|
12
|
+
# Args wire layout:
|
|
13
|
+
# [key-related params: protocol + key_id + counterparty + privileged]
|
|
14
|
+
# [33 bytes: verifier compressed pubkey]
|
|
15
|
+
module Args
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
def serialize(args)
|
|
19
|
+
verifier = args[:verifier]
|
|
20
|
+
raise BSV::Wallet::InvalidParameterError.new('verifier', 'a 33-byte binary pubkey or 66-char hex') unless verifier
|
|
21
|
+
|
|
22
|
+
w = BSV::Wallet::Wire::Writer.new
|
|
23
|
+
Common.write_key_related_params(
|
|
24
|
+
w,
|
|
25
|
+
protocol_id: args[:protocol_id],
|
|
26
|
+
key_id: args[:key_id],
|
|
27
|
+
counterparty: args[:counterparty],
|
|
28
|
+
privileged: args[:privileged],
|
|
29
|
+
privileged_reason: args[:privileged_reason]
|
|
30
|
+
)
|
|
31
|
+
w.write_bytes(pubkey_bytes(verifier))
|
|
32
|
+
w.buf
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def deserialize(bytes)
|
|
36
|
+
r = BSV::Wallet::Wire::Reader.new(bytes)
|
|
37
|
+
params = Common.read_key_related_params(r)
|
|
38
|
+
verifier = r.read_bytes(PUBKEY_SIZE)
|
|
39
|
+
params.merge(verifier: verifier)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def pubkey_bytes(value)
|
|
43
|
+
return value.b if value.is_a?(String) && value.bytesize == PUBKEY_SIZE
|
|
44
|
+
|
|
45
|
+
[value.to_s].pack('H*')
|
|
46
|
+
end
|
|
47
|
+
private_class_method :pubkey_bytes
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Result wire layout:
|
|
51
|
+
# [33 bytes: prover pubkey]
|
|
52
|
+
# [33 bytes: verifier pubkey]
|
|
53
|
+
# [33 bytes: counterparty pubkey]
|
|
54
|
+
# [1 byte: security_level][VarInt protocol_name_len][protocol_name bytes]
|
|
55
|
+
# [VarInt key_id_len][key_id bytes]
|
|
56
|
+
# [VarInt encrypted_linkage_len][encrypted_linkage bytes]
|
|
57
|
+
# [VarInt encrypted_linkage_proof_len][encrypted_linkage_proof bytes]
|
|
58
|
+
# [1 byte: proof_type]
|
|
59
|
+
module Result
|
|
60
|
+
module_function
|
|
61
|
+
|
|
62
|
+
def serialize(result)
|
|
63
|
+
w = BSV::Wallet::Wire::Writer.new
|
|
64
|
+
w.write_bytes(pubkey_bytes(result[:prover]))
|
|
65
|
+
w.write_bytes(pubkey_bytes(result[:verifier]))
|
|
66
|
+
w.write_bytes(pubkey_bytes(result[:counterparty]))
|
|
67
|
+
Common.write_protocol(w, result[:protocol_id])
|
|
68
|
+
key_id_bytes = result[:key_id].to_s.b
|
|
69
|
+
w.write_varint(key_id_bytes.bytesize)
|
|
70
|
+
w.write_bytes(key_id_bytes)
|
|
71
|
+
encrypted_linkage = Common.to_binary(result[:encrypted_linkage])
|
|
72
|
+
w.write_varint(encrypted_linkage.bytesize)
|
|
73
|
+
w.write_bytes(encrypted_linkage)
|
|
74
|
+
encrypted_linkage_proof = Common.to_binary(result[:encrypted_linkage_proof])
|
|
75
|
+
w.write_varint(encrypted_linkage_proof.bytesize)
|
|
76
|
+
w.write_bytes(encrypted_linkage_proof)
|
|
77
|
+
w.write_byte(result[:proof_type].to_i)
|
|
78
|
+
w.buf
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def deserialize(bytes)
|
|
82
|
+
r = BSV::Wallet::Wire::Reader.new(bytes)
|
|
83
|
+
prover = r.read_bytes(PUBKEY_SIZE)
|
|
84
|
+
verifier = r.read_bytes(PUBKEY_SIZE)
|
|
85
|
+
counterparty = r.read_bytes(PUBKEY_SIZE)
|
|
86
|
+
protocol_id = Common.read_protocol(r)
|
|
87
|
+
key_id_len = r.read_varint
|
|
88
|
+
key_id = r.read_bytes(key_id_len).force_encoding('UTF-8')
|
|
89
|
+
el_len = r.read_varint
|
|
90
|
+
encrypted_linkage = r.read_bytes(el_len)
|
|
91
|
+
elp_len = r.read_varint
|
|
92
|
+
encrypted_linkage_proof = r.read_bytes(elp_len)
|
|
93
|
+
proof_type = r.read_byte
|
|
94
|
+
{
|
|
95
|
+
prover: prover,
|
|
96
|
+
verifier: verifier,
|
|
97
|
+
counterparty: counterparty,
|
|
98
|
+
protocol_id: protocol_id,
|
|
99
|
+
key_id: key_id,
|
|
100
|
+
encrypted_linkage: encrypted_linkage,
|
|
101
|
+
encrypted_linkage_proof: encrypted_linkage_proof,
|
|
102
|
+
proof_type: proof_type
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def pubkey_bytes(value)
|
|
107
|
+
return value.b if value.is_a?(String) && value.bytesize == PUBKEY_SIZE
|
|
108
|
+
|
|
109
|
+
[value.to_s].pack('H*')
|
|
110
|
+
end
|
|
111
|
+
private_class_method :pubkey_bytes
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 serialiser for sign_action args (call byte 2).
|
|
7
|
+
#
|
|
8
|
+
# Wire layout (port of go-sdk/wallet/serializer/sign_action_args.go):
|
|
9
|
+
# [varint] spends count
|
|
10
|
+
# For each spend (sorted by input_index):
|
|
11
|
+
# [varint] input_index
|
|
12
|
+
# [int_bytes] unlocking_script
|
|
13
|
+
# [optional_uint32] sequence_number
|
|
14
|
+
# [int_bytes] reference
|
|
15
|
+
# [1 byte] options present flag (0=absent, 1=present)
|
|
16
|
+
# If options present:
|
|
17
|
+
# [optional_bool] accept_delayed_broadcast
|
|
18
|
+
# [optional_bool] return_txid_only
|
|
19
|
+
# [optional_bool] no_send
|
|
20
|
+
# [txid_slice] send_with
|
|
21
|
+
module SignActionArgs
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
# @param args [Hash]
|
|
25
|
+
# @return [String] binary
|
|
26
|
+
def serialize(args)
|
|
27
|
+
w = Wire::Writer.new
|
|
28
|
+
|
|
29
|
+
spends = args[:spends] || {}
|
|
30
|
+
w.write_varint(spends.length)
|
|
31
|
+
spends.keys.sort.each do |idx|
|
|
32
|
+
spend = spends[idx]
|
|
33
|
+
w.write_varint(idx)
|
|
34
|
+
w.write_int_bytes(spend[:unlocking_script])
|
|
35
|
+
w.write_optional_uint32(spend[:sequence_number])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
w.write_int_bytes(args[:reference])
|
|
39
|
+
|
|
40
|
+
opts = args[:options]
|
|
41
|
+
if opts
|
|
42
|
+
w.write_byte(1)
|
|
43
|
+
w.write_optional_bool(opts[:accept_delayed_broadcast])
|
|
44
|
+
w.write_optional_bool(opts[:return_txid_only])
|
|
45
|
+
w.write_optional_bool(opts[:no_send])
|
|
46
|
+
w.write_txid_slice(opts[:send_with])
|
|
47
|
+
else
|
|
48
|
+
w.write_byte(0)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
w.buf
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @param bytes [String] binary
|
|
55
|
+
# @return [Hash]
|
|
56
|
+
def deserialize(bytes)
|
|
57
|
+
r = Wire::Reader.new(bytes)
|
|
58
|
+
|
|
59
|
+
spend_count = r.read_varint
|
|
60
|
+
spends = {}
|
|
61
|
+
spend_count.times do
|
|
62
|
+
idx = r.read_varint
|
|
63
|
+
script = r.read_int_bytes
|
|
64
|
+
seq = r.read_optional_uint32
|
|
65
|
+
spend = { unlocking_script: script }
|
|
66
|
+
spend[:sequence_number] = seq unless seq.nil?
|
|
67
|
+
spends[idx] = spend
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
reference = r.read_int_bytes
|
|
71
|
+
|
|
72
|
+
options_present = r.read_byte
|
|
73
|
+
options = if options_present == 1
|
|
74
|
+
opts = {}
|
|
75
|
+
v = r.read_optional_bool
|
|
76
|
+
opts[:accept_delayed_broadcast] = v unless v.nil?
|
|
77
|
+
v = r.read_optional_bool
|
|
78
|
+
opts[:return_txid_only] = v unless v.nil?
|
|
79
|
+
v = r.read_optional_bool
|
|
80
|
+
opts[:no_send] = v unless v.nil?
|
|
81
|
+
sw = r.read_txid_slice
|
|
82
|
+
opts[:send_with] = sw unless sw.nil?
|
|
83
|
+
opts
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
result = { spends: spends }
|
|
87
|
+
result[:reference] = reference unless reference.nil? || reference.empty?
|
|
88
|
+
result[:options] = options unless options.nil?
|
|
89
|
+
result
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 serialiser for sign_action result (call byte 2).
|
|
7
|
+
#
|
|
8
|
+
# Wire layout (port of go-sdk/wallet/serializer/sign_action_result.go):
|
|
9
|
+
# [flag + 32 bytes] txid with flag byte: 0=absent, 1=present (wire-order)
|
|
10
|
+
# [flag + int_bytes] tx (BEEF bytes) with flag byte: 0=absent, 1=present + varint_len
|
|
11
|
+
# [send_with_results] varint count + txid (32 bytes) + status_byte each
|
|
12
|
+
module SignActionResult
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# @param result [Hash]
|
|
16
|
+
# @return [String] binary
|
|
17
|
+
def serialize(result)
|
|
18
|
+
w = Wire::Writer.new
|
|
19
|
+
|
|
20
|
+
txid_bytes = result[:txid] ? [result[:txid]].pack('H*').reverse : nil
|
|
21
|
+
w.write_optional_bytes_with_flag(txid_bytes, fixed_size: 32)
|
|
22
|
+
w.write_optional_bytes_with_flag(result[:tx])
|
|
23
|
+
|
|
24
|
+
Common.write_send_with_results(w, result[:send_with_results])
|
|
25
|
+
|
|
26
|
+
w.buf
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @param bytes [String] binary
|
|
30
|
+
# @return [Hash]
|
|
31
|
+
def deserialize(bytes)
|
|
32
|
+
r = Wire::Reader.new(bytes)
|
|
33
|
+
|
|
34
|
+
txid_raw = r.read_optional_bytes_with_flag(fixed_size: 32)
|
|
35
|
+
txid_hex = txid_raw&.reverse&.unpack1('H*')
|
|
36
|
+
tx = r.read_optional_bytes_with_flag
|
|
37
|
+
|
|
38
|
+
send_with_results = Common.read_send_with_results(r)
|
|
39
|
+
|
|
40
|
+
result = {}
|
|
41
|
+
result[:txid] = txid_hex unless txid_hex.nil?
|
|
42
|
+
result[:tx] = tx unless tx.nil?
|
|
43
|
+
result[:send_with_results] = send_with_results unless send_with_results.nil?
|
|
44
|
+
result
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 serialisers for is_authenticated (call byte 23) and
|
|
7
|
+
# wait_for_authentication (call byte 24).
|
|
8
|
+
#
|
|
9
|
+
# Both calls take no args payload (originator is in the frame header).
|
|
10
|
+
#
|
|
11
|
+
# Result wire format:
|
|
12
|
+
# is_authenticated: [1 byte] 0x01 = true, 0x00 = false
|
|
13
|
+
# wait_for_authentication: empty payload → always returns authenticated: true
|
|
14
|
+
#
|
|
15
|
+
# Port of go-sdk/wallet/serializer/authenticated.go.
|
|
16
|
+
module IsAuthenticated
|
|
17
|
+
module Args
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
def serialize(_args = {})
|
|
21
|
+
''.b
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def deserialize(_bytes)
|
|
25
|
+
{}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module Result
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# @param result [Hash] { authenticated: Boolean }
|
|
33
|
+
# @return [String] 1-byte binary
|
|
34
|
+
def serialize(result)
|
|
35
|
+
[result[:authenticated] ? 1 : 0].pack('C')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param bytes [String] binary — must be exactly 1 byte
|
|
39
|
+
# @return [Hash] { authenticated: Boolean }
|
|
40
|
+
def deserialize(bytes)
|
|
41
|
+
data = bytes.b
|
|
42
|
+
unless data.bytesize == 1
|
|
43
|
+
raise BSV::Wallet::InvalidParameterError.new(
|
|
44
|
+
'is_authenticated result',
|
|
45
|
+
'exactly 1 byte'
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
{ authenticated: data.getbyte(0) == 1 }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module WaitForAuthentication
|
|
55
|
+
module Args
|
|
56
|
+
module_function
|
|
57
|
+
|
|
58
|
+
def serialize(_args = {})
|
|
59
|
+
''.b
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def deserialize(_bytes)
|
|
63
|
+
{}
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module Result
|
|
68
|
+
module_function
|
|
69
|
+
|
|
70
|
+
# @param _result [Hash] ignored — always serialises as empty payload
|
|
71
|
+
# @return [String] empty binary
|
|
72
|
+
def serialize(_result = {})
|
|
73
|
+
''.b
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @param _bytes [String] ignored — always returns authenticated: true
|
|
77
|
+
# @return [Hash] { authenticated: true }
|
|
78
|
+
def deserialize(_bytes = nil)
|
|
79
|
+
{ authenticated: true }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 wire codec for the +verify_hmac+ call (call byte 14).
|
|
7
|
+
#
|
|
8
|
+
# Port of go-sdk/wallet/serializer/verify_hmac.go.
|
|
9
|
+
module VerifyHmac
|
|
10
|
+
HMAC_SIZE = 32
|
|
11
|
+
|
|
12
|
+
# Args wire layout:
|
|
13
|
+
# [key-related params]
|
|
14
|
+
# [32 bytes: HMAC]
|
|
15
|
+
# [VarInt data_len][data bytes]
|
|
16
|
+
# [optional_bool seek_permission]
|
|
17
|
+
module Args
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
def serialize(args)
|
|
21
|
+
hmac = Common.to_binary(args[:hmac])
|
|
22
|
+
raise BSV::Wallet::InvalidParameterError.new('hmac', "exactly #{HMAC_SIZE} bytes") unless hmac.bytesize == HMAC_SIZE
|
|
23
|
+
|
|
24
|
+
w = BSV::Wallet::Wire::Writer.new
|
|
25
|
+
Common.write_key_related_params(
|
|
26
|
+
w,
|
|
27
|
+
protocol_id: args[:protocol_id],
|
|
28
|
+
key_id: args[:key_id],
|
|
29
|
+
counterparty: args[:counterparty],
|
|
30
|
+
privileged: args[:privileged],
|
|
31
|
+
privileged_reason: args[:privileged_reason]
|
|
32
|
+
)
|
|
33
|
+
w.write_bytes(hmac)
|
|
34
|
+
data = Common.to_binary(args[:data])
|
|
35
|
+
w.write_varint(data.bytesize)
|
|
36
|
+
w.write_bytes(data)
|
|
37
|
+
w.write_optional_bool(args[:seek_permission])
|
|
38
|
+
w.buf
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def deserialize(bytes)
|
|
42
|
+
r = BSV::Wallet::Wire::Reader.new(bytes)
|
|
43
|
+
params = Common.read_key_related_params(r)
|
|
44
|
+
hmac = r.read_bytes(HMAC_SIZE)
|
|
45
|
+
data_len = r.read_varint
|
|
46
|
+
data = r.read_bytes(data_len)
|
|
47
|
+
seek_permission = r.read_optional_bool
|
|
48
|
+
params.merge(hmac: hmac, data: data, seek_permission: seek_permission)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Result wire layout: empty — success implies valid.
|
|
53
|
+
module Result
|
|
54
|
+
module_function
|
|
55
|
+
|
|
56
|
+
def serialize(_result)
|
|
57
|
+
''.b
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def deserialize(_bytes)
|
|
61
|
+
{ valid: true }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
module Serializer
|
|
6
|
+
# BRC-103 wire codec for the +verify_signature+ call (call byte 16).
|
|
7
|
+
#
|
|
8
|
+
# Port of go-sdk/wallet/serializer/verify_signature.go.
|
|
9
|
+
module VerifySignature
|
|
10
|
+
HASH_SIZE = 32
|
|
11
|
+
|
|
12
|
+
# Args wire layout:
|
|
13
|
+
# [key-related params]
|
|
14
|
+
# [optional_bool for_self]
|
|
15
|
+
# [VarInt sig_len][DER signature bytes]
|
|
16
|
+
# [1 byte: data-type flag — 1=data, 2=hash_to_directly_verify]
|
|
17
|
+
# If flag=1: [VarInt data_len][data bytes]
|
|
18
|
+
# If flag=2: [32 bytes: hash]
|
|
19
|
+
# [optional_bool seek_permission]
|
|
20
|
+
module Args
|
|
21
|
+
module_function
|
|
22
|
+
|
|
23
|
+
def serialize(args)
|
|
24
|
+
data = args[:data] && Common.to_binary(args[:data])
|
|
25
|
+
hash = args[:hash_to_directly_verify] && Common.to_binary(args[:hash_to_directly_verify])
|
|
26
|
+
sig = args[:signature] && Common.to_binary(args[:signature])
|
|
27
|
+
|
|
28
|
+
if data && hash
|
|
29
|
+
raise BSV::Wallet::InvalidParameterError.new(
|
|
30
|
+
'data and hash_to_directly_verify',
|
|
31
|
+
'not both provided — supply one or the other'
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
raise BSV::Wallet::InvalidParameterError.new('data or hash_to_directly_verify', 'present') unless data || hash
|
|
35
|
+
raise BSV::Wallet::InvalidParameterError.new('signature', 'present') unless sig
|
|
36
|
+
|
|
37
|
+
w = BSV::Wallet::Wire::Writer.new
|
|
38
|
+
Common.write_key_related_params(
|
|
39
|
+
w,
|
|
40
|
+
protocol_id: args[:protocol_id],
|
|
41
|
+
key_id: args[:key_id],
|
|
42
|
+
counterparty: args[:counterparty],
|
|
43
|
+
privileged: args[:privileged],
|
|
44
|
+
privileged_reason: args[:privileged_reason]
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
w.write_optional_bool(args[:for_self])
|
|
48
|
+
|
|
49
|
+
w.write_varint(sig.bytesize)
|
|
50
|
+
w.write_bytes(sig)
|
|
51
|
+
|
|
52
|
+
if data
|
|
53
|
+
w.write_byte(1)
|
|
54
|
+
w.write_varint(data.bytesize)
|
|
55
|
+
w.write_bytes(data)
|
|
56
|
+
else
|
|
57
|
+
w.write_byte(2)
|
|
58
|
+
w.write_bytes(hash)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
w.write_optional_bool(args[:seek_permission])
|
|
62
|
+
w.buf
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def deserialize(bytes)
|
|
66
|
+
r = BSV::Wallet::Wire::Reader.new(bytes)
|
|
67
|
+
params = Common.read_key_related_params(r)
|
|
68
|
+
for_self = r.read_optional_bool
|
|
69
|
+
sig_len = r.read_varint
|
|
70
|
+
signature = r.read_bytes(sig_len)
|
|
71
|
+
flag = r.read_byte
|
|
72
|
+
payload = case flag
|
|
73
|
+
when 1
|
|
74
|
+
len = r.read_varint
|
|
75
|
+
{ data: r.read_bytes(len) }
|
|
76
|
+
when 2
|
|
77
|
+
{ hash_to_directly_verify: r.read_bytes(HASH_SIZE) }
|
|
78
|
+
else
|
|
79
|
+
raise ArgumentError, "invalid data-type flag: #{flag}"
|
|
80
|
+
end
|
|
81
|
+
seek_permission = r.read_optional_bool
|
|
82
|
+
params.merge(for_self: for_self, signature: signature).merge(payload).merge(seek_permission: seek_permission)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Result wire layout: empty — success implies valid.
|
|
87
|
+
module Result
|
|
88
|
+
module_function
|
|
89
|
+
|
|
90
|
+
def serialize(_result)
|
|
91
|
+
''.b
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def deserialize(_bytes)
|
|
95
|
+
{ valid: true }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|