public bool Equals(CfdKeyData other) { if (KeyType != other.KeyType) { return(false); } else if (KeyType == CfdDescriptorKeyType.Bip32) { return(ExtPubkey.Equals(other.ExtPubkey)); } else if (KeyType == CfdDescriptorKeyType.Bip32Priv) { return(ExtPrivkey.Equals(other.ExtPrivkey)); } else if (KeyType == CfdDescriptorKeyType.Public) { return(Pubkey.Equals(other.Pubkey)); } else if (KeyType == CfdDescriptorKeyType.SchnorrPubkey) { return(SchnorrPubkey.Equals(other.SchnorrPubkey)); } else { return(false); } }
/// <summary> /// Constructor. (empty) /// </summary> public SignParameter() { data = ""; signatureHashType = new SignatureHashType(CfdSighashType.All, false); pubkey = new Pubkey(); isSetDerEncode = false; }
public ExtPubkey(CfdNetworkType networkType, Pubkey parentPubkey, Pubkey pubkey, ByteData chainCode, uint depth, uint childNumber) { if (parentPubkey is null) { throw new ArgumentNullException(nameof(parentPubkey)); } if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } if (chainCode is null) { throw new ArgumentNullException(nameof(chainCode)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdCreateExtkey( handle.GetHandle(), (int)networkType, (int)CfdExtKeyType.Pubkey, parentPubkey.ToHexString(), "", pubkey.ToHexString(), chainCode.ToHexString(), (byte)depth, childNumber, out IntPtr tempExtkey); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } extkey = CCommon.ConvertToString(tempExtkey); this.networkType = networkType; this.pubkey = pubkey; this.chainCode = chainCode; this.depth = depth; this.childNumber = childNumber; GetExtkeyInformation(handle, extkey, out version, out fingerprint, out _, out _, out _, out _); } }
/// <summary> /// constructor for pubkey. /// </summary> /// <param name="pubkey">public key</param> /// <param name="type">address type</param> /// <param name="network">network type</param> public Address(Pubkey pubkey, CfdAddressType type, CfdNetworkType network) { if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdCreateAddress( handle.GetHandle(), (int)type, pubkey.ToHexString(), "", (int)network, out IntPtr outputAddress, out IntPtr outputLockingScript, out IntPtr outputP2shSegwitLockingScript); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } address = CCommon.ConvertToString(outputAddress); lockingScript = CCommon.ConvertToString(outputLockingScript); p2shSegwitLockingScript = CCommon.ConvertToString(outputP2shSegwitLockingScript); Initialize(handle, address, out network, out witnessVersion, out string tempLockingScript, out hash); addressType = type; } }
/// <summary> /// Get pegin address. /// </summary> /// <param name="fedpegScript">fedpeg script</param> /// <param name="pubkey">pubkey</param> /// <param name="hashType">hash type</param> /// <param name="network">network type</param> /// <returns>pegin address data</returns> public static PeginData GetPeginAddress(Script fedpegScript, Pubkey pubkey, CfdHashType hashType, CfdNetworkType network) { if (fedpegScript is null) { throw new ArgumentNullException(nameof(fedpegScript)); } if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdGetPeginAddress( handle.GetHandle(), (int)network, fedpegScript.ToHexString(), (int)hashType, pubkey.ToHexString(), "", out IntPtr outputPeginAddress, out IntPtr outputClaimScript, out IntPtr outputFedpegScript); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } string peginAddress = CCommon.ConvertToString(outputPeginAddress); string claimScript = CCommon.ConvertToString(outputClaimScript); string tweakedFedpegScript = CCommon.ConvertToString(outputFedpegScript); return(new PeginData(new Address(peginAddress), new Script(claimScript), new Script(tweakedFedpegScript))); } }
public CfdKeyData(ExtPrivkey extPrivkey) { KeyType = CfdDescriptorKeyType.Bip32Priv; Pubkey = new Pubkey(); ExtPubkey = new ExtPubkey(); ExtPrivkey = extPrivkey; }
public CfdKeyData(Pubkey pubkey) { KeyType = CfdDescriptorKeyType.Public; Pubkey = pubkey; ExtPubkey = new ExtPubkey(); ExtPrivkey = new ExtPrivkey(); }
/// <summary> /// Sign ECDSA-adaptor. /// </summary> /// <param name="msg">32-byte msg</param> /// <param name="secretKey">secret key</param> /// <param name="adaptor">adaptor pubkey</param> /// <returns>ECDSA-adaptor pair</returns> public static AdaptorPair Sign(ByteData msg, Privkey secretKey, Pubkey adaptor) { if (msg is null) { throw new ArgumentNullException(nameof(msg)); } if (secretKey is null) { throw new ArgumentNullException(nameof(secretKey)); } if (adaptor is null) { throw new ArgumentNullException(nameof(adaptor)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdSignEcdsaAdaptor( handle.GetHandle(), msg.ToHexString(), secretKey.ToHexString(), adaptor.ToHexString(), out IntPtr signature, out IntPtr proof); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } string tempSig = CCommon.ConvertToString(signature); string tempProof = CCommon.ConvertToString(proof); return(new AdaptorPair(new ByteData(tempSig), new ByteData(tempProof))); } }
public CfdKeyData(SchnorrPubkey schnorrPubkey) { KeyType = CfdDescriptorKeyType.SchnorrPubkey; Pubkey = new Pubkey(); ExtPubkey = new ExtPubkey(); ExtPrivkey = new ExtPrivkey(); SchnorrPubkey = schnorrPubkey; }
public CfdKeyData(ExtPubkey extPubkey) { KeyType = CfdDescriptorKeyType.Bip32; Pubkey = new Pubkey(); ExtPubkey = extPubkey; ExtPrivkey = new ExtPrivkey(); SchnorrPubkey = new SchnorrPubkey(); }
public CfdKeyData(CfdDescriptorKeyType keyType, Pubkey pubkey, ExtPubkey extPubkey, ExtPrivkey extPrivkey) { KeyType = keyType; Pubkey = pubkey; ExtPubkey = extPubkey; ExtPrivkey = extPrivkey; }
/// <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 ExtPubkey(string base58String) { if (base58String is null) { throw new ArgumentNullException(nameof(base58String)); } extkey = base58String; using (var handle = new ErrorHandle()) { GetExtkeyInformation(handle, extkey, out version, out fingerprint, out chainCode, out depth, out childNumber, out networkType); pubkey = GetPubkeyFromExtKey(handle, extkey, networkType); } }
/// <summary> /// Get Schnorr public key from public key. /// </summary> /// <param name="pubkey">public key</param> /// <param name="parity">parity flag</param> /// <returns>schnorr pubkey</returns> public static SchnorrPubkey GetPubkeyFromPubkey(Pubkey pubkey, out bool parity) { if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdGetSchnorrPubkeyFromPubkey( handle.GetHandle(), pubkey.ToHexString(), out IntPtr schnorrPubkey, out parity); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } string data = CCommon.ConvertToString(schnorrPubkey); return(new SchnorrPubkey(data)); } }
public override int GetHashCode() { if (KeyType == CfdDescriptorKeyType.Bip32) { return(KeyType.GetHashCode() + ExtPubkey.GetHashCode()); } else if (KeyType == CfdDescriptorKeyType.Bip32Priv) { return(KeyType.GetHashCode() + ExtPrivkey.GetHashCode()); } else if (KeyType == CfdDescriptorKeyType.Public) { return(KeyType.GetHashCode() + Pubkey.GetHashCode()); } else { return(KeyType.GetHashCode()); } }
/// <summary> /// Verify ECDSA-adaptor signature. /// </summary> /// <param name="adaptorSignature">adaptor signature</param> /// <param name="adaptorProof">adaptor proof</param> /// <param name="adaptor">adaptor pubkey</param> /// <param name="msg">32-byte msg</param> /// <param name="pubkey">pubkey</param> /// <returns>verify result</returns> public static bool Verify(ByteData adaptorSignature, ByteData adaptorProof, Pubkey adaptor, ByteData msg, Pubkey pubkey) { if (adaptorSignature is null) { throw new ArgumentNullException(nameof(adaptorSignature)); } if (adaptorProof is null) { throw new ArgumentNullException(nameof(adaptorProof)); } if (adaptor is null) { throw new ArgumentNullException(nameof(adaptor)); } if (msg is null) { throw new ArgumentNullException(nameof(msg)); } if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdVerifyEcdsaAdaptor( handle.GetHandle(), adaptorSignature.ToHexString(), adaptorProof.ToHexString(), adaptor.ToHexString(), msg.ToHexString(), pubkey.ToHexString()); if (ret == CfdErrorCode.Success) { return(true); } else if (ret != CfdErrorCode.SignVerificationError) { handle.ThrowError(ret); } } return(false); }
/// <summary> /// constructor by address string. /// </summary> /// <param name="addressString">address string.</param> public ConfidentialAddress(string addressString) { confidentialAddress = addressString; using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdParseConfidentialAddress( handle.GetHandle(), addressString, out IntPtr address, out IntPtr confidentialKey, out int networkType); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } var unconfidenialAddressStr = CCommon.ConvertToString(address); var keyStr = CCommon.ConvertToString(confidentialKey); unconfidenialAddress = new Address(unconfidenialAddressStr); key = new Pubkey(keyStr); } }
/// <summary> /// constructor. /// </summary> /// <param name="address">address</param> /// <param name="confidentialKey">confidential key</param> public ConfidentialAddress(Address address, Pubkey confidentialKey) { if (address is null) { throw new ArgumentNullException(nameof(address)); } if (confidentialKey is null) { throw new ArgumentNullException(nameof(confidentialKey)); } unconfidenialAddress = address; key = confidentialKey; using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdCreateConfidentialAddress( handle.GetHandle(), address.ToAddressString(), confidentialKey.ToHexString(), out IntPtr outputConfidentialAddr); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } confidentialAddress = CCommon.ConvertToString(outputConfidentialAddr); } }
public bool Equals(TaprootScriptData other) { return(Pubkey.Equals(other.Pubkey) && ControlBlock.Equals(other.ControlBlock) && TapScript.Equals(other.TapScript)); }
public override int GetHashCode() { return(Pubkey.GetHashCode() + ControlBlock.GetHashCode() + TapScript.GetHashCode()); }
/// <summary> /// Extract ECDSA-adaptor secret key. /// </summary> /// <param name="adaptorSignature">adaptor signature</param> /// <param name="signature">signature</param> /// <param name="adaptor">adaptor pubkey</param> /// <returns>secret key</returns> public static Privkey ExtractSecret(ByteData adaptorSignature, ByteData signature, Pubkey adaptor) { if (adaptorSignature is null) { throw new ArgumentNullException(nameof(adaptorSignature)); } if (signature is null) { throw new ArgumentNullException(nameof(signature)); } if (adaptor is null) { throw new ArgumentNullException(nameof(adaptor)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdExtractEcdsaAdaptorSecret( handle.GetHandle(), adaptorSignature.ToHexString(), signature.ToHexString(), adaptor.ToHexString(), out IntPtr secret); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } string sk = CCommon.ConvertToString(secret); return(new Privkey(sk)); } }
/// <summary> /// set signature's related pubkey. /// </summary> /// <param name="relatedPubkey">pubkey</param> public void SetRelatedPubkey(Pubkey relatedPubkey) { pubkey = relatedPubkey; }