Skip to content

Instantly share code, notes, and snippets.

@imyourm8
Last active June 20, 2018 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imyourm8/3a98ae96642653733dee194c59dba1a1 to your computer and use it in GitHub Desktop.
Save imyourm8/3a98ae96642653733dee194c59dba1a1 to your computer and use it in GitHub Desktop.
Generate Private Key for Loom Using BIP39
// Add this function to Loom SDK CryptoUtils.cs
public static byte[] GeneratePrivateKey(byte[] seed) {
byte[] publicKey32;
byte[] privateKey64;
Ed25519.KeyPairFromSeed(out publicKey32, out privateKey64, seed);
return privateKey64;
}
// You can use any BIP39 implementation. In this example i used https://github.com/ByronAP/BIP39.NET-Portable
var mnemonic = "spin sunset pact nature enhance include fatigue occur blind wire inner foot";
var importer = new Bitcoin.BIP39.BIP39(mnemonic);
var seed = new byte[32];
for(int i = 0; i < 32; ++i) {
seed[i] = importer.SeedBytes[i]; // use only first 32 bytes
}
PrivateKey = Loom.Unity3d.CryptoUtils.GeneratePrivateKey(seed); // generate private key - ready to use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment