Bitcoin Stack Alternate is a query and reply website for Bitcoin crypto-currency fanatics. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
One of the best solutions are voted up and rise to the highest
Requested
Considered
1k occasions
I need to take a non-public key as enter from the person and convert it to a pockets tackle utilizing C#.
I’ve seen this in a tutorial to generate a random key:
Key privateKey = new Key();
PubKey publicKey = privateKey.PubKey;
Console.WriteLine(publicKey.GetAddress(ScriptPubKeyType.Legacy, Community.Most important));
How do I convert a non-public key string from the person to a pockets tackle for foremost web?
Assuming the non-public key string on this instance is pk
Console.WriteLine("Enter non-public key:");
string pk = Console.ReadLine();
var bitcoinPrivateKey = new BitcoinSecret(pk, Community.Most important);
var legacy_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Legacy);
Console.WriteLine("Legacy Tackle :" + legacy_address);
And if you wish to get p2sh-segwit and bech32 tackle, add beneath traces:
var p2shsegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.SegwitP2SH);
var nativesegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Segwit);
Console.WriteLine("P2SH-Segwit Tackle :" + p2shsegwit_address);
Console.WriteLine("Bech32 Tackle :" + nativesegwit_address);
2
I’ve carried out it by javascript, perhaps it could show you how to.
//utilization:
//$ yarn add bip32 bip39
// node --version is 16.1.0
const bs58check = require('bs58check');
const bip39 = require("bip39");
const bip32 = require("bip32");
const createHash = require('create-hash');
perform addr(node) {
var hash = node.identifier; // hash160 of the publicKey
const payload = Buffer.allocUnsafe(21);
var model = 0x0;
payload.writeUInt8(model, 0);
hash.copy(payload, 1);
var tackle = bs58check.encode(payload);
return tackle;
}
var puzzle = "some puzzle you inputting";
var entropy = createHash("sha256").replace(puzzle).digest().toString("hex");
console.log("entropy: " + entropy);
var mnemonic = bip39.entropyToMnemonic(entropy);
console.log("mnemonic: " + mnemonic);
var passphrase = "";
var seed = bip39.mnemonicToSeedSync(mnemonic, passphrase);
var grasp = bip32.fromSeed(seed); // m
// generate 10 btc addresses...
for (var i = 0; i < 3; i++) {
var node = grasp.derivePath("m/44'/0'/0'/1/" + i);
var tackle = addr(node);
console.log("BTC #" + i + ": " + tackle);
}
You’ll find data find out how to calculate Public key from Non-public right here https://bitcoin-math.000webhostapp.com Additionally, you’ll find Doubling, Addition and Scalar multiply features on C# with out NBitcoin class Key, BigInteger is used solely.