forked from 33cn/chain33-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.py
34 lines (30 loc) · 1.23 KB
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from crypto import signer, address
from crypto.gm import sm2
from crypto.ed25519 import ed25519Signer
class Account():
def __init__(self, privateKey, publicKey, address, signType):
self.privateKey = privateKey
self.publicKey = publicKey
self.address = address
self.signType = signType
def newAccount(signType=signer.SECP256K1):
if signType == signer.SECP256K1:
privateKey = signer.generatePrivateKey()
publicKey = signer.publicKeyFromPrivate(privateKey)
addr = address.pubKeyToAddr(publicKey)
return Account(privateKey, publicKey, addr, signType)
elif signType == signer.SM2:
sm2Util = sm2.SM2Util()
privateKey,_ = sm2Util.genetateKey()
publicKey = sm2Util.pubKeyFromPrivate(privateKey)
addr = address.pubKeyToAddr(publicKey)
return Account(privateKey, publicKey, addr, signType)
elif signType == signer.ED25519:
privateKey = ed25519Signer.generatePrivateKey()
publicKey = ed25519Signer.publicKeyFromPrivate(privateKey)
addr = address.pubKeyToAddr(publicKey)
return Account(privateKey, publicKey, addr, signType)
else:
raise ValueError(
"Error: signType is not correct."
)