Skip to content

Commit 7523be6

Browse files
Add contract signature to strkey (#259)
Co-authored-by: David Roldán <Odraxs@users.noreply.github.com>
1 parent 71eafaf commit 7523be6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/strkey/strkey.ex

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ defmodule StellarBase.StrKey do
3333
# Base32-encodes to 'M...'
3434
muxed_account: 12 <<< 3,
3535
# Base32-encodes to 'P...'
36-
signed_payload: 15 <<< 3
36+
signed_payload: 15 <<< 3,
37+
# Base32-encodes to 'C...'
38+
contract: 2 <<< 3
3739
]
3840

3941
@spec encode(data :: binary_data(), version :: version()) ::

test/strkey/strkey_test.exs

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule StellarBase.StrKeyTest do
1111
pre_auth_tx: "TBAUEQ2EIVDEOSCJJJFUYTKOJ5IFCUSTKRAUEQ2EIVDEOSCJJJAUCYSF",
1212
signed_payload:
1313
"PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAQACAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4DUPB6IBZGM",
14+
contract: "CCEMOFO5TE7FGOAJOA3RDHPC6RW3CFXRVIGOFQPFE4ZGOKA2QEA636SN",
1415
ed25519_public_key_binary:
1516
<<140, 41, 54, 138, 42, 205, 199, 107, 245, 247, 190, 85, 36, 15, 30, 168, 67, 63, 52,
1617
183, 198, 97, 56, 146, 34, 127, 90, 21, 230, 0, 172, 89>>,
@@ -27,7 +28,10 @@ defmodule StellarBase.StrKeyTest do
2728
<<63, 12, 52, 191, 147, 173, 13, 153, 113, 208, 76, 204, 144, 247, 5, 81, 28, 131, 138,
2829
173, 151, 52, 164, 162, 251, 13, 122, 3, 252, 127, 232, 154, 0, 0, 0, 32, 1, 2, 3, 4, 5,
2930
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
30-
29, 30, 31, 32>>
31+
29, 30, 31, 32>>,
32+
contract_binary:
33+
<<136, 199, 21, 221, 153, 62, 83, 56, 9, 112, 55, 17, 157, 226, 244, 109, 177, 22, 241,
34+
170, 12, 226, 193, 229, 39, 50, 103, 40, 26, 129, 1, 237>>
3135
}
3236
end
3337

@@ -55,6 +59,10 @@ defmodule StellarBase.StrKeyTest do
5559
test "signed_payload", %{signed_payload: signed_payload, signed_payload_binary: binary} do
5660
{:ok, ^signed_payload} = StrKey.encode(binary, :signed_payload)
5761
end
62+
63+
test "contract", %{contract: contract, contract_binary: binary} do
64+
{:ok, ^contract} = StrKey.encode(binary, :contract)
65+
end
5866
end
5967

6068
describe "encode!/2" do
@@ -83,6 +91,10 @@ defmodule StellarBase.StrKeyTest do
8391
test "signed_payload", %{signed_payload: signed_payload, signed_payload_binary: binary} do
8492
^signed_payload = StrKey.encode!(binary, :signed_payload)
8593
end
94+
95+
test "contract", %{contract: contract, contract_binary: binary} do
96+
^contract = StrKey.encode!(binary, :contract)
97+
end
8698
end
8799

88100
describe "decode/2" do
@@ -110,6 +122,10 @@ defmodule StellarBase.StrKeyTest do
110122
{:ok, ^binary} = StrKey.decode(signed_payload, :signed_payload)
111123
end
112124

125+
test "contract", %{contract: contract, contract_binary: binary} do
126+
{:ok, ^binary} = StrKey.decode(contract, :contract)
127+
end
128+
113129
test "invalid version byte", %{muxed_account: muxed_account} do
114130
{:error, :unmatched_version_bytes} = StrKey.decode(muxed_account, :ed25519_public_key)
115131
end
@@ -150,6 +166,10 @@ defmodule StellarBase.StrKeyTest do
150166
^binary = StrKey.decode!(signed_payload, :signed_payload)
151167
end
152168

169+
test "contract", %{contract: contract, contract_binary: binary} do
170+
^binary = StrKey.decode!(contract, :contract)
171+
end
172+
153173
test "invalid version byte", %{muxed_account: muxed_account} do
154174
assert_raise StrKeyError, "version bytes does not match", fn ->
155175
StrKey.decode!(muxed_account, :ed25519_public_key)

0 commit comments

Comments
 (0)