/// <summary> /// constructor for schnorr pubkey. /// </summary> /// <param name="pubkey">schnorr public key</param> /// <param name="type">address type</param> /// <param name="network">network type</param> public Address(SchnorrPubkey 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); this.network = network; addressType = type; } }
/// <summary> /// Get taproot data. /// </summary> /// <param name="internalPubkey">internal pubkey</param> /// <returns>taproot data</returns> public TaprootScriptData GetTaprootData(SchnorrPubkey internalPubkey) { if (internalPubkey is null) { throw new ArgumentNullException(nameof(internalPubkey)); } using (var handle = new ErrorHandle()) using (var treeHandle = new TreeHandle(handle)) { Load(handle, treeHandle); var ret = NativeMethods.CfdGetTaprootScriptTreeHash( handle.GetHandle(), treeHandle.GetHandle(), internalPubkey.ToHexString(), out IntPtr witnessProgram, out IntPtr tapLeafHashPtr, out IntPtr controlBlockStr); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } var witnessProgramStr = CCommon.ConvertToString(witnessProgram); var tapLeafHash = CCommon.ConvertToString(tapLeafHashPtr); var controlBlock = CCommon.ConvertToString(controlBlockStr); return(new TaprootScriptData( new SchnorrPubkey(witnessProgramStr), new ByteData(controlBlock), new ByteData256(tapLeafHash), GetTapScript())); } }
/// <summary> /// Constructor. /// </summary> /// <param name="controlBlock">control block</param> /// <param name="tapscript">tapscript</param> public TaprootScriptTree(ByteData controlBlock, Script tapscript) { if (controlBlock is null) { throw new ArgumentNullException(nameof(controlBlock)); } if (tapscript is null) { throw new ArgumentNullException(nameof(tapscript)); } using (var handle = new ErrorHandle()) using (var treeHandle = new TreeHandle(handle)) { var ret = NativeMethods.CfdSetTapScriptByWitnessStack(handle.GetHandle(), treeHandle.GetHandle(), controlBlock.ToHexString(), tapscript.ToHexString(), out IntPtr internalPubkeyPtr); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } internalPubkey = new SchnorrPubkey(CCommon.ConvertToString(internalPubkeyPtr)); GetAllData(handle, treeHandle); } }
/// <summary> /// Constructor. (empty) /// </summary> public SchnorrSignature() { data = ""; nonce = new SchnorrPubkey(); key = new Privkey(); sighashType = new SignatureHashType(CfdSighashType.Default, false); }
/// <summary> /// Verify schnorr signature. /// </summary> /// <param name="signature">schnorr signature</param> /// <param name="msg">32-byte msg</param> /// <param name="schnorrPubkey">pubkey</param> /// <returns>verify result</returns> public static bool Verify(SchnorrSignature signature, ByteData msg, SchnorrPubkey schnorrPubkey) { if (signature is null) { throw new ArgumentNullException(nameof(signature)); } if (msg is null) { throw new ArgumentNullException(nameof(msg)); } if (schnorrPubkey is null) { throw new ArgumentNullException(nameof(schnorrPubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdVerifySchnorr( handle.GetHandle(), signature.ToHexString(), msg.ToHexString(), schnorrPubkey.ToHexString()); if (ret == CfdErrorCode.Success) { return(true); } else if (ret != CfdErrorCode.SignVerificationError) { handle.ThrowError(ret); } } return(false); }
/// <summary> /// Compute signature point. /// </summary> /// <param name="msg">32-byte msg</param> /// <param name="nonce">schnorr nonce</param> /// <param name="schnorrPubkey">pubkey</param> /// <returns>signature point</returns> public static Pubkey ComputeSigPoint(ByteData msg, SchnorrPubkey nonce, SchnorrPubkey schnorrPubkey) { if (msg is null) { throw new ArgumentNullException(nameof(msg)); } if (nonce is null) { throw new ArgumentNullException(nameof(nonce)); } if (schnorrPubkey is null) { throw new ArgumentNullException(nameof(schnorrPubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdComputeSchnorrSigPoint( handle.GetHandle(), msg.ToHexString(), nonce.ToHexString(), schnorrPubkey.ToHexString(), out IntPtr sigPoint); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } string point = CCommon.ConvertToString(sigPoint); return(new Pubkey(point)); } }
public CfdKeyData(Pubkey pubkey) { KeyType = CfdDescriptorKeyType.Public; Pubkey = pubkey; ExtPubkey = new ExtPubkey(); ExtPrivkey = new ExtPrivkey(); SchnorrPubkey = new SchnorrPubkey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="pubkey">schnorr pubkey</param> /// <param name="controlBlock">control block</param> /// <param name="tapLeafHash">tapleaf hash</param> /// <param name="tapScript">tapscript</param> public TaprootScriptData(SchnorrPubkey pubkey, ByteData controlBlock, ByteData256 tapLeafHash, Script tapScript) { Pubkey = pubkey; ControlBlock = controlBlock; TapLeafHash = tapLeafHash; TapScript = tapScript; }
public CfdKeyData(SchnorrPubkey schnorrPubkey) { KeyType = CfdDescriptorKeyType.SchnorrPubkey; Pubkey = new Pubkey(); ExtPubkey = new ExtPubkey(); ExtPrivkey = new ExtPrivkey(); SchnorrPubkey = schnorrPubkey; }
public CfdKeyData(ExtPrivkey extPrivkey) { KeyType = CfdDescriptorKeyType.Bip32Priv; Pubkey = new Pubkey(); ExtPubkey = new ExtPubkey(); ExtPrivkey = extPrivkey; SchnorrPubkey = new SchnorrPubkey(); }
public CfdKeyData(CfdDescriptorKeyType keyType, Pubkey pubkey, ExtPubkey extPubkey, ExtPrivkey extPrivkey) { KeyType = keyType; Pubkey = pubkey; ExtPubkey = extPubkey; ExtPrivkey = extPrivkey; SchnorrPubkey = new SchnorrPubkey(); }
/// <summary> /// Set default internal pubkey. /// </summary> /// <param name="pubkey">internal pubkey</param> public void SetInternalPubkey(SchnorrPubkey pubkey) { if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } else if (pubkey.IsValid()) { internalPubkey = pubkey; } }
/// <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="origin">source branch.</param> public TaprootScriptTree(TapBranch origin) { if (origin is null) { throw new ArgumentNullException(nameof(origin)); } var script = new Script(); if (origin.HasTapScript()) { script = origin.GetTapScript(); } Initialize(origin.ToString(), script, origin.GetTargetNodes()); internalPubkey = new SchnorrPubkey(); using (var handle = new ErrorHandle()) using (var treeHandle = new TreeHandle(handle)) { Load(handle, treeHandle); GetAllData(handle, treeHandle); } }
/// <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); } }
/// <summary> /// Constructor. (default) /// </summary> public TaprootScriptTree() { internalPubkey = new SchnorrPubkey(); }
/// <summary> /// Constructor. (empty) /// </summary> public SchnorrSignature() { data = ""; nonce = new SchnorrPubkey(); key = new Privkey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="tapscript">tapscript</param> /// <param name="leafVersion">leaf version</param> public TaprootScriptTree(Script tapscript, byte leafVersion) : base(tapscript, leafVersion) { internalPubkey = new SchnorrPubkey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="treeStr">script tree string.</param> /// <param name="tapscript">tapscript</param> public TaprootScriptTree(string treeStr, Script tapscript) : base(treeStr, tapscript) { internalPubkey = new SchnorrPubkey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="treeStr">script tree string.</param> /// <param name="tapscript">tapscript</param> /// <param name="targetNodes">branch hash list.</param> public TaprootScriptTree(string treeStr, Script tapscript, ByteData256[] targetNodes) : base(treeStr, tapscript, targetNodes) { internalPubkey = new SchnorrPubkey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="tapscript">tapscript</param> public TaprootScriptTree(Script tapscript) : base(tapscript) { internalPubkey = new SchnorrPubkey(); }