How to convert seeds into private key? - flutter

how to convert bip39 mnemonic seed phrase into private key without any libraries like web3 or ethers.js
basically I'm trying to replicate my metamasks wallets private key
so I would like to write a function that takes my seed words as my input and return the private key for ethereum based wallets
privateKey = function([seed_1, seed_2, ..., seed_12]);
Where do I get started?

#elangovan you can use dart's BIP32 implementation and follow below steps
Convert Mnemonic(12 words) to seed using bip32.mnemonicToSeed
Seedto HD Master Node using bip32.BIP32.fromSeed
Derive child node at desired HD path(m/44'/0')
However, you can derive public and private keys from the child node.

Related

Connect to a node with a String identifier

I'm trying to write a generic OPC-UA connector with Eclipse Milo.
Reading data from nodes already works fine when I'm using numeric nodeIDs, such as ns=0;i=2258. In milo I can simple construct the nodeID like this for example:
NodeId nodeIdentifier = new NodeId(Unsigned.ushort(nameSpaceID), uint(nodeID));
and it works fine.
But when I'm trying to connect to a note with a string identifier of a production node that only have a string identifier like shown in this image
the process fails with a StatusCode{name=Bad_NodeIdUnknown, value=0x80340000, quality=bad} exception.
I create the nodeIdentifier like this NodeId nodeIdentifier = NodeId.parse(nodeIDString);
and the parsed value looked like this:
ns=1;s=t|023_Messwert
First things first, you can’t just decide to use a string-based NodeId because you feel like it. If the server is exposing it as an integer-based NodeId then that’s what you have to use, as is the case with the CurrentTime Node being identified by ns=0;i=2258.
Parsing a string-based NodeId via NodeId.parse will work fine as long as it’s in the right format. What value are you trying to parse?

How to do SSL public key pinning in flutter/dart?

relatively new to Flutter here (and programming in general). Only familiar with the more basic stuffs but I've now encountered the need to use a CertificatePinner such as this in flutter/dart:
https://square.github.io/okhttp/3.x/okhttp/okhttp3/CertificatePinner.html (I've successfully implemented this in my previous kotlin/java project in android studio). My goal is to pin public key (not certificate)
All I have is the public key in the form of a string like shown below, nothing else:
"sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
How do I go about achieving this? I've asked this in an open issue on github but haven't gotten any responses yet (https://github.com/dart-lang/sdk/issues/35981). Hoping someone has managed to achieve this.
I've also scoured through other sources. I think the closest one to a solution for me is How can I do public key pinning in Flutter?
but I don't quite get what is being done there and I can't comment to ask questions there since I don't have enough reputation yet.
For comparison, all I want to do is achieve the same thing in flutter/dart what I could in java/kotlin with these few lines of code:
String hostname = "publicobject.com";
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(hostname, "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
.build();
Thanks for your help
Start with the code in the answer you refer to. That takes the certificate in DER format and starts decoding it.
ASN1Parser p = ASN1Parser(der);
ASN1Sequence signedCert = p.nextObject() as ASN1Sequence;
ASN1Sequence cert = signedCert.elements[0] as ASN1Sequence;
ASN1Sequence pubKeyElement = cert.elements[6] as ASN1Sequence;
// this is the Subject Public Key element, which describes the type of key and actual value
For example, if we decode the certificate of pub.dev we find that it's an RSA key with a modulus of 65537 and a value of 2347......:
SEQUENCE (2 elem)
SEQUENCE (2 elem)
OBJECT IDENTIFIER 1.2.840.113549.1.1.1 rsaEncryption (PKCS #1)
NULL
BIT STRING (1 elem)
SEQUENCE (2 elem)
INTEGER (2048 bit) 234782553149463204049153749736864715384123240676730175743244004248041…
INTEGER 65537
From the RFC, the SPKI fingerprint is the SHA-256 hash of this whole element.
// you need to import dart:convert and package:crypto/crypto.dart
var hash = base64.encode(sha256.convert(pubKeyElement.contentBytes()).bytes);
var spkiFingerprint = 'sha256/$hash'; // should match the value you have
Caveats
The badCertificateCallback doesn't deliver the whole certificate chain, so you can't walk up the whole chain. What's worse is that it doesn't always seem to deliver the leaf certificate! Sometimes it delivers an intermediate certificate.

How to add the same childByAutoID under multiple structures in Firebase using Swift?

To create a new value, I use...
Database.database().reference().child("checklists").childByAutoId().setValue(["title":title,"imageUrl":imageUrl])
How can I take that .childByAutoId value created and set it under another structure like below?
I manually created the value using...
Database.database().reference().child("users").child(uid).child("checklists").childByAutoId().setValue(["listID":"-Lm21a-rDc6qBPcfpVUw"])
How can I do it automatically?
When you call childByAutoId() it returns a DatabaseReference to the new location. On that reference you can either write a value, or for example get its key. With the latter you can then write the same key in another location (either as the key of a node, or its value).
So something like:
let ref = Database.database().reference().child("checklists").childByAutoId()
ref.setValue(["title":title,"imageUrl":imageUrl])
Database.database().reference().child("users").child(uid).child("checklists")
.childByAutoId().setValue(["listID":ref.key])
You can also use that key, in case you want another node with the same key:
Database.database().reference().child("users").child(uid).child("checklists")
.child(ref.key).setValue("yay!")

Rundeck - dynamic mapping for ssh keys

I am looking into importing my nodes using the EC2 plugin
My mapping is setup to import the key as one of the values, but I don't seem to be able to figure out how to concatenate the dynamic value coming from the node with the string that will represent the ssh key path. Effectively what I would like to achieve is something along those lines:
ssh-keypath.default=/path/to/key/directory/${keyName}.pem;
this, however sets my keypath to literal "/path/to/key/directory/${keyName}.pem"
I figured out how to do this:
In Mapping Params i set keyName.selector=keyName;
In Default Node Executor / SSH Key File path i can now set /path/to/keys/${node.keyName}.pem
This means that if I add all of my keys to /path/to/keys/ they will load dynamically as long as the keyName is correct.

Generate RSA keypair in perl efficently with custom PRNG

I would want to generate a public and private keypair, effciently (fast) in perl, and be able to input random data for myself.
With inputting random data, I of course mean, that the function requires lets say X random bits to generate a public/private keypair of Y bits, and I should be able to supply these X bits to the function.
So idially, the function should look like:
($private, $public) = genRSAkeypair($randomdata, 1024);
and $private then contains:
----BEGIN RSA PRIVATE KEY-----
....
----END ....
and $public contains
----BEGIN RSA PUBLIC and so on...
$randomdata is then just a string of random bits from any random generator. If $randomdata is consistent between instance1 and instance2, instance1 and instance2 should return the same public and private keys.
If you want to know what the use of this is, is that I plan to make a password-based RSA key generation system, without any need to store any keys anywhere. So the key is generated straight out from the password, by using SHA512 chained in a specific way to create static random data.
Of course, the same public and private key must be returned everytime the same password is entered in the system, else the system would be useless.
Any ideas?
I would try Crypt::OpenSSL::RSA, it seems to bind
directly to libssl