/// <summary> /// Derive returns the network-specific address associated with a public key. /// Blockchains that require an on-chain action to create an account should not implement this method. /// </summary> /// <param name="request"></param> /// <returns></returns> public JObject ConstructionDerive(ConstructionDeriveRequest request) { if (request.NetworkIdentifier?.Blockchain?.ToLower() != "neo n3") { return(Error.NETWORK_IDENTIFIER_INVALID.ToJson()); } if (request.NetworkIdentifier?.Network?.ToLower() != network) { return(Error.NETWORK_IDENTIFIER_INVALID.ToJson()); } if (request.PublicKey.CurveType != CurveType.Secp256r1) { return(Error.CURVE_NOT_SUPPORTED.ToJson()); } ECPoint pubKey; try { pubKey = ECPoint.FromBytes(request.PublicKey.HexBytes.HexToBytes(), ECCurve.Secp256r1); } catch (Exception) { return(Error.INVALID_PUBLIC_KEY.ToJson()); } string address = Contract.CreateSignatureRedeemScript(pubKey).ToScriptHash().ToAddress(system.Settings.AddressVersion); ConstructionDeriveResponse response = new ConstructionDeriveResponse(new AccountIdentifier(address)); return(response.ToJson()); }
/// <summary> /// Derive returns the network-specific address associated with a public key. /// Blockchains that require an on-chain action to create an account should not implement this method. /// </summary> /// <param name="request"></param> /// <returns></returns> public JObject ConstructionDerive(ConstructionDeriveRequest request) { if (request.PublicKey.CurveType != CurveType.Secp256r1) { return(Error.CURVE_NOT_SUPPORTED.ToJson()); } ECPoint pubKey; try { pubKey = ECPoint.FromBytes(request.PublicKey.Bytes, ECCurve.Secp256r1); } catch (Exception) { return(Error.INVALID_PUBLIC_KEY.ToJson()); } string address = ("21" + pubKey.EncodePoint(true).ToHexString() + "ac").HexToBytes().ToScriptHash().ToAddress(); ConstructionDeriveResponse response = new ConstructionDeriveResponse(address); return(response.ToJson()); }