Skip to content

Commit 8081668

Browse files
update to v0.0.2 (#5)
* upgrade: update to cryptogarageinc/v0.0.2 # Conflicts: # src/ConfidentialTransaction.cs # test/CfdTestMain.cs * upgrade: update reference version (cfd: v0.0.6) Co-authored-by: k-matsuzawa <[email protected]>
1 parent 0c49d95 commit 8081668

17 files changed

+1165
-60
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,6 @@ external/*
191191
/go.sum
192192
/cover.html
193193
*.log
194+
195+
/out/
196+
/.vs/

external/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if(CFD_TARGET_VERSION)
3333
set(CFD_TARGET_TAG ${CFD_TARGET_VERSION})
3434
message(STATUS "[external project local] cfd target=${CFD_TARGET_VERSION}")
3535
else()
36-
set(CFD_TARGET_TAG v0.0.5)
36+
set(CFD_TARGET_TAG v0.0.6)
3737
endif()
3838
if(CFD_TARGET_URL)
3939
set(CFD_TARGET_REP ${CFD_TARGET_URL})

src/Address.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Cfd
88
/**
99
* @brief network type
1010
*/
11-
public enum CfdNetworkType
11+
public enum CfdNetworkType : int
1212
{
1313
Mainnet = 0, //!< btc mainnet
1414
Testnet, //!< btc testnet
@@ -21,7 +21,7 @@ public enum CfdNetworkType
2121
/**
2222
* @brief address type
2323
*/
24-
public enum CfdAddressType
24+
public enum CfdAddressType : int
2525
{
2626
P2sh = 1, //!< Legacy address (Script Hash)
2727
P2pkh, //!< Legacy address (PublicKey Hash)
@@ -34,7 +34,7 @@ public enum CfdAddressType
3434
/**
3535
* @brief hash type
3636
*/
37-
public enum CfdHashType
37+
public enum CfdHashType : int
3838
{
3939
P2sh = 1, //!< Script Hash
4040
P2pkh, //!< PublicKey Hash
@@ -47,7 +47,7 @@ public enum CfdHashType
4747
/**
4848
* @brief witness version
4949
*/
50-
public enum CfdWitnessVersion
50+
public enum CfdWitnessVersion : int
5151
{
5252
VersionNone = -1, //!< Missing WitnessVersion
5353
Version0 = 0, //!< version 0

src/BlindFactor.cs

+33
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Cfd
1010
/// </summary>
1111
public class BlindFactor
1212
{
13+
public const uint Size = 32;
1314
private readonly string hexString;
1415

1516
/// <summary>
@@ -26,9 +27,31 @@ public BlindFactor()
2627
/// <param name="blindFactorHex">blinder hex</param>
2728
public BlindFactor(string blindFactorHex)
2829
{
30+
if (string.IsNullOrEmpty(blindFactorHex))
31+
{
32+
hexString = "0000000000000000000000000000000000000000000000000000000000000000";
33+
}
34+
else if ((blindFactorHex == null) || (blindFactorHex.Length != Size * 2))
35+
{
36+
CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to blindFactor size.");
37+
}
2938
hexString = blindFactorHex;
3039
}
3140

41+
/// <summary>
42+
/// Constructor. (valid blind factor)
43+
/// </summary>
44+
/// <param name="blindFactorHex">blinder</param>
45+
public BlindFactor(byte[] bytes)
46+
{
47+
if ((bytes == null) || (bytes.Length != Size))
48+
{
49+
CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to blindFactor size.");
50+
}
51+
var blindFactorBytes = CfdCommon.ReverseBytes(bytes);
52+
this.hexString = StringUtil.FromBytes(blindFactorBytes);
53+
}
54+
3255
/// <summary>
3356
/// blinder hex string.
3457
/// </summary>
@@ -37,5 +60,15 @@ public string ToHexString()
3760
{
3861
return hexString;
3962
}
63+
64+
/// <summary>
65+
/// blinder byte array.
66+
/// </summary>
67+
/// <returns>blinder byte array</returns>
68+
public byte[] GetBytes()
69+
{
70+
var blindFactorBytes = StringUtil.ToBytes(hexString);
71+
return CfdCommon.ReverseBytes(blindFactorBytes);
72+
}
4073
}
4174
}

src/ByteData.cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/// <summary>
2+
/// cfd library namespace.
3+
/// </summary>
4+
namespace Cfd
5+
{
6+
/// <summary>
7+
/// byte data class.
8+
/// </summary>
9+
public class ByteData
10+
{
11+
private string data;
12+
13+
/// <summary>
14+
/// Constructor. (empty)
15+
/// </summary>
16+
public ByteData()
17+
{
18+
data = "";
19+
}
20+
21+
/// <summary>
22+
/// Constructor.
23+
/// </summary>
24+
/// <param name="bytes">byte array</param>
25+
public ByteData(byte[] bytes)
26+
{
27+
if (bytes == null)
28+
{
29+
CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to bytes is null.");
30+
}
31+
data = StringUtil.FromBytes(bytes);
32+
}
33+
34+
/// <summary>
35+
/// Constructor.
36+
/// </summary>
37+
/// <param name="hex">hex string</param>
38+
public ByteData(string hex)
39+
{
40+
if (hex == null)
41+
{
42+
CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to hex is null.");
43+
}
44+
data = hex;
45+
}
46+
47+
/// <summary>
48+
/// hex string.
49+
/// </summary>
50+
/// <returns>hex string</returns>
51+
public string ToHexString()
52+
{
53+
return data;
54+
}
55+
56+
/// <summary>
57+
/// byte array.
58+
/// </summary>
59+
/// <returns>byte array</returns>
60+
public byte[] ToBytes()
61+
{
62+
return StringUtil.ToBytes(data);
63+
}
64+
}
65+
}

src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ target_sources(${PROJECT_NAME}
140140
Txid.cs
141141
Address.cs
142142
BlindFactor.cs
143+
ByteData.cs
143144
CfdCommon.cs
144145
CMakeLists.txt
145146
CoinUtil.cs
@@ -153,9 +154,12 @@ target_sources(${PROJECT_NAME}
153154
Privkey.cs
154155
Pubkey.cs
155156
Script.cs
157+
ScriptUtil.cs
156158
ScriptWitness.cs
159+
SignParameter.cs
157160
StringUtil.cs
158161
Transaction.cs
162+
UtxoData.cs
159163
)
160164

161165
target_compile_options(${PROJECT_NAME}

0 commit comments

Comments
 (0)