create_ipfsnodeid_from_tmp_secret.dunikey.py
This commit is contained in:
parent
dc904751e8
commit
a719820ccb
Binary file not shown.
|
@ -1,14 +1,13 @@
|
|||
#!/usr/bin/env python3
|
||||
# This Python script gets Duniter creddentials as arguments, and writes a PubSec file that should be compatible with Cesium and Silkaj(DuniterPy) clients.
|
||||
# It also create ipfs Identity
|
||||
# This Python script gets /tmp/secret.dunikey produce with key_create_dunikey.py or from https://Cesium.app
|
||||
# It create ED25519 ipfs (currently 0.7.0) Identity
|
||||
#########################################################################
|
||||
# sudo apt install protobuf-compiler
|
||||
# pip3 install base58 google protobuf duniterpy
|
||||
# wget https://github.com/libp2p/go-libp2p-core/raw/master/crypto/pb/crypto.proto
|
||||
# protoc --python_out=. crypto.proto
|
||||
#########################################################################
|
||||
# launch with :
|
||||
# python3 key_create_dnuikey_and_ipfs.py <id> <mdp>
|
||||
|
||||
import os
|
||||
import base58
|
||||
import base64
|
||||
|
@ -16,16 +15,8 @@ import cryptography.hazmat.primitives.asymmetric.ed25519 as ed25519
|
|||
from cryptography.hazmat.primitives import serialization
|
||||
import crypto_pb2
|
||||
from sys import argv
|
||||
from duniterpy.key import SigningKey
|
||||
|
||||
# path to save to
|
||||
path = "/tmp/secret.dunikey"
|
||||
|
||||
key = SigningKey.from_credentials(argv[1], argv[2], None)
|
||||
key.save_pubsec_file(path)
|
||||
print(
|
||||
key.pubkey,
|
||||
)
|
||||
# TODO controls
|
||||
# Capturing keys (from /tmp/secret.dunikey)
|
||||
shared_key = os.popen('cat /tmp/secret.dunikey | grep pub | cut -d " " -f 2').read()
|
||||
secure_key = os.popen('cat /tmp/secret.dunikey | grep sec | cut -d " " -f 2').read()
|
||||
|
@ -45,6 +36,7 @@ ipfs_secure_bytes = ipfs_secure.private_bytes(encoding=serialization.Encoding.Ra
|
|||
|
||||
# Formulating PeerID
|
||||
ipfs_pid = base58.b58encode(b'\x00$\x08\x01\x12 ' + ipfs_shared_bytes)
|
||||
PeerID = ipfs_pid.decode('ascii')
|
||||
print('Peer ID: {}'.format(ipfs_pid.decode('ascii')))
|
||||
|
||||
|
||||
|
@ -52,4 +44,8 @@ print('Peer ID: {}'.format(ipfs_pid.decode('ascii')))
|
|||
pkey = crypto_pb2.PrivateKey()
|
||||
pkey.Type = crypto_pb2.KeyType.Ed25519
|
||||
pkey.Data = ipfs_secure_bytes + ipfs_shared_bytes
|
||||
PrivKey = base64.b64encode(pkey.SerializeToString()).decode('ascii')
|
||||
print('Private key: {}'.format(base64.b64encode(pkey.SerializeToString()).decode('ascii')))
|
||||
|
||||
# jq '.Identity.PeerID="$PeerID"' ~/.ipfs/config
|
||||
# jq '.Identity.PrivKey="$PeerID"' ~/.ipfs/config
|
Loading…
Reference in New Issue