/// <summary> /// Constructor. /// </summary> /// <param name="bytes">byte array</param> public SchnorrPubkey(byte[] bytes) { if ((bytes == null) || (bytes.Length != Size)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to pubkey size."); } data = StringUtil.FromBytes(bytes); }
/// <summary> /// Constructor. /// </summary> /// <param name="hex">hex string</param> public SchnorrPubkey(string hex) { if ((hex == null) || (hex.Length != Size * 2)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to pubkey size."); } data = hex; }
public ByteData ToDerEncode() { if (!isSetDerEncode) { CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "Failed to unset der encode flag."); } return(ToDerEncode(signatureHashType)); }
/// <summary> /// get bytes from array. /// </summary> /// <param name="index">array index</param> /// <returns>byte array</returns> public byte[] GetBytes(uint index) { if (index >= hexArray.Length) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to index."); } return(StringUtil.ToBytes(hexArray[index])); }
/// <summary> /// get hex string from array. /// </summary> /// <param name="index">array index</param> /// <returns>hex string</returns> public string ToHexString(uint index) { if (index >= hexArray.Length) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to index."); } return(hexArray[index]); }
/// <summary> /// Get tapscript if existing tapscript on branch root. /// </summary> /// <returns></returns> public Script GetTapScript() { if (tapscript.IsEmpty()) { CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "tapscript not found."); } return(tapscript); }
public Txid(string txid) { if ((txid == null) || (txid.Length != Size * 2)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to txid size."); } this.txid = txid; }
public TapBranch GetScriptTree() { if (!HasTapScript()) { CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "Failed to unused script tree."); } return(rootData.ScriptTree); }
public CfdKeyData GetKeyData() { if (rootData.KeyData.KeyType == CfdDescriptorKeyType.Null) { CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "Failed to script hash or multisig key."); } return(rootData.KeyData); }
public Txid(byte[] bytes) { if ((bytes == null) || (bytes.Length != Size)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to txid size."); } var txidBytes = CfdCommon.ReverseBytes(bytes); txid = StringUtil.FromBytes(txidBytes); }
/// <summary> /// Constructor. /// </summary> /// <param name="bytes">byte data array</param> public SignParameter(byte[] bytes) { if (bytes == null) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to txid size."); } data = StringUtil.FromBytes(bytes); signatureHashType = new SignatureHashType(CfdSighashType.All, false); pubkey = new Pubkey(); isSetDerEncode = false; }
/// <summary> /// Constructor. /// </summary> /// <param name="hex">byte data hex</param> public SignParameter(string hex) { if (hex == null) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to txid size."); } data = hex; signatureHashType = new SignatureHashType(CfdSighashType.All, false); pubkey = new Pubkey(); isSetDerEncode = false; }
public CfdKeyData[] GetMultisigKeyList() { if ((HasKeyHash()) || (rootData.MultisigRequireNum == 0)) { CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "Failed to script hash or multisig key."); } CfdKeyData[] keyList = new CfdKeyData[rootData.MultisigKeyList.Count]; rootData.MultisigKeyList.CopyTo(keyList); return(keyList); }
/// <summary> /// Constructor. /// </summary> /// <param name="bytes">privkey byte array</param> public Privkey(byte[] bytes) { if ((bytes == null) || (bytes.Length != Size)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to privkey size."); } privkey = StringUtil.FromBytes(bytes); networkType = CfdNetworkType.Mainnet; privkeyWif = ""; isCompressed = true; }
/// <summary> /// Constructor. /// </summary> /// <param name="hex">hex string</param> public SchnorrSignature(string hex) { if ((hex == null) || (hex.Length != Size * 2)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to signature size."); } data = hex; string[] list = Verify(data); nonce = new SchnorrPubkey(list[0]); key = new Privkey(list[1]); }
/// <summary> /// Constructor. /// </summary> /// <param name="bytes">byte array</param> public SchnorrSignature(byte[] bytes) { if ((bytes == null) || (bytes.Length != Size)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to signature size."); } data = StringUtil.FromBytes(bytes); string[] list = Verify(data); nonce = new SchnorrPubkey(list[0]); key = new Privkey(list[1]); }
/// <summary> /// constructor. /// </summary> /// <param name="asset">asset string.</param> public ConfidentialAsset(string asset) { if (asset is null) { throw new ArgumentNullException(nameof(asset)); } if ((asset.Length != Size * 2) && (asset.Length != CommitmentSize * 2)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to asset size."); } commitment = asset; }
/// <summary> /// Add branch. /// </summary> /// <param name="hash">branch hash.</param> public void AddBranch(ByteData hash) { if (hash is null) { throw new ArgumentNullException(nameof(hash)); } if (hash.GetSize() != 32) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Invalid branch hash size."); } AddBranch(hash.ToHexString()); }
/// <summary> /// Constructor. /// </summary> /// <param name="bytes">pubkey byte array</param> public Pubkey(byte[] bytes) { if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } else if (bytes.Length > UncompressLength) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to pubkey size."); } pubkey = StringUtil.FromBytes(bytes); // check format Validate(pubkey); }
/// <summary> /// Constructor. /// </summary> /// <param name="pubkeyHex">pubkey hex string</param> public Pubkey(string pubkeyHex) { if (pubkeyHex is null) { throw new ArgumentNullException(nameof(pubkeyHex)); } else if (pubkeyHex.Length > UncompressLength * 2) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to pubkey size."); } pubkey = pubkeyHex; // check format Validate(pubkey); }
public Script GetRedeemScript() { switch (rootData.HashType) { case CfdHashType.P2sh: case CfdHashType.P2wsh: case CfdHashType.P2shP2wsh: return(rootData.RedeemScript); default: CfdCommon.ThrowError(CfdErrorCode.IllegalStateError, "Failed to unused script descriptor."); return(null); } }
/// <summary> /// constructor. /// </summary> /// <param name="bytes">script byte array.</param> public Script(byte[] bytes) { if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length > MaxSize) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to script size."); } script = StringUtil.FromBytes(bytes); using (var handle = new ErrorHandle()) { scriptItems = ParseScript(handle, script); } }
/// <summary> /// constructor. /// </summary> /// <param name="scriptHex">script hex string</param> public Script(string scriptHex) { if (scriptHex is null) { throw new ArgumentNullException(nameof(scriptHex)); } if (scriptHex.Length > MaxSize * 2) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to script size."); } script = scriptHex; using (var handle = new ErrorHandle()) { scriptItems = ParseScript(handle, scriptHex); } }
/// <summary> /// constructor /// </summary> /// <param name="hash">branch hash</param> public TapBranch(ByteData256 hash) { if (hash is null) { throw new ArgumentNullException(nameof(hash)); } if (hash.GetSize() != 32) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Invalid branch hash size."); } treeString = hash.ToHexString(); targetNodes = Array.Empty <ByteData256>(); branches = Array.Empty <TapBranch>(); topHash = hash; tapscript = new Script(); leafVersion = 0; }
/// <summary> /// combine pubkeys. /// </summary> /// <param name="pubkeyList">pubkey list</param> /// <returns>combined pubkey</returns> public static Pubkey Combine(Pubkey[] pubkeyList) { if (pubkeyList is null) { throw new ArgumentNullException(nameof(pubkeyList)); } else if (pubkeyList.Length < 2) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to pubkey list length. minimum length is 2."); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdInitializeCombinePubkey( handle.GetHandle(), out IntPtr combineHandle); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } try { foreach (Pubkey pubkeyItem in pubkeyList) { ret = NativeMethods.CfdAddCombinePubkey( handle.GetHandle(), combineHandle, pubkeyItem.ToHexString()); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } } ret = NativeMethods.CfdFinalizeCombinePubkey( handle.GetHandle(), combineHandle, out IntPtr combinedKey); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } return(new Pubkey(CCommon.ConvertToString(combinedKey))); } finally { NativeMethods.CfdFreeCombinePubkeyHandle(handle.GetHandle(), combineHandle); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="bytes">byte array</param> public ByteData256(byte[] bytes) { if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length == 0) { data = emptyString; } else if (bytes.Length != Size) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to ByteData256 size."); } else { data = StringUtil.FromBytes(bytes); } hasReverse = false; }
/// <summary> /// constructor. /// </summary> /// <param name="asset">asset bytes.</param> public ConfidentialAsset(byte[] asset) { if (asset is null) { throw new ArgumentNullException(nameof(asset)); } if ((asset.Length != Size) && (asset.Length != CommitmentSize)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to asset size."); } if (asset.Length == Size) { var assetBytes = CfdCommon.ReverseBytes(asset); commitment = StringUtil.FromBytes(assetBytes); } else { commitment = StringUtil.FromBytes(asset); } }
/// <summary> /// Constructor. /// </summary> /// <param name="hex">hex string</param> /// <param name="hasReverse">reversed data</param> public ByteData256(string hex, bool hasReverse) { if (hex is null) { throw new ArgumentNullException(nameof(hex)); } if (hex.Length == 0) { data = emptyString; } else if (hex.Length != Size * 2) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to ByteData256 size."); } else { data = hex; } this.hasReverse = hasReverse; }
/// <summary> /// Throw exception from error handle and error code. /// </summary> /// <param name="errorCode">error code</param> /// <exception cref="ArgumentOutOfRangeException">argument range exception</exception> /// <exception cref="ArgumentException">argument exception</exception> /// <exception cref="InsufficientMemoryException">memory full exception</exception> /// <exception cref="InvalidOperationException">illegal exception</exception> public void ThrowError(CfdErrorCode errorCode) { if ((errorCode == CfdErrorCode.Success) || disposed) { return; } string errorMessage; var ret = CCommon.CfdGetLastErrorMessage(handle, out IntPtr messageAddress); if (ret == CfdErrorCode.Success) { string message = CCommon.ConvertToString(messageAddress); errorMessage = $"CFD error[{errorCode}] message:{message}"; } else { errorMessage = $"CFD error[{errorCode}]"; } CfdCommon.ThrowError(errorCode, errorMessage); }
/// <summary> /// Constructor. /// </summary> /// <param name="hex">hex string</param> public SchnorrSignature(string hex) { if (hex is null) { throw new ArgumentNullException(nameof(hex)); } if ((hex.Length != Size * 2) && (hex.Length != AddedSigHashTypeSize * 2)) { CfdCommon.ThrowError(CfdErrorCode.IllegalArgumentError, "Failed to signature size."); } data = hex; string[] list = Verify(data); nonce = new SchnorrPubkey(list[0]); key = new Privkey(list[1]); if (hex.Length == AddedSigHashTypeSize * 2) { sighashType = CollectSigHashType(data); } else { sighashType = new SignatureHashType(CfdSighashType.Default, false); } }