forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
81 lines (56 loc) · 2.48 KB
/
helper.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
from plenum.common.signer_did import DidSigner
from plenum.common.util import friendlyToRaw, rawToFriendly
from sovrin_client.client.wallet.wallet import Wallet
from sovrin_common.config_util import getConfig
from stp_core.crypto.util import ed25519PkToCurve25519
def processInvAccept(wallet, msg):
pass
def rawVerkeyToPubkey(raw_verkey):
return ed25519PkToCurve25519(raw_verkey)
def friendlyVerkeyToPubkey(verkey):
vkRaw = friendlyToRaw(verkey)
pkraw = ed25519PkToCurve25519(vkRaw)
return rawToFriendly(pkraw)
def getClaimVersionFileName(agentName):
return agentName.replace(" ", "-").lower() + "-schema-version.txt"
def updateAndGetNextClaimVersionNumber(basedirpath, fileName):
claimVersionFilePath = '{}/{}'.format(basedirpath, fileName)
# get version number from file
claimVersionNumber = 0.01
if os.path.isfile(claimVersionFilePath):
with open(claimVersionFilePath, mode='r+') as file:
claimVersionNumber = float(file.read()) + 0.001
file.seek(0)
# increment version and update file
file.write(str(claimVersionNumber))
file.truncate()
else:
with open(claimVersionFilePath, mode='w') as file:
file.write(str(claimVersionNumber))
return claimVersionNumber
def build_wallet_core(wallet_name, seed_file):
config = getConfig()
baseDir = os.path.expanduser(config.baseDir)
seedFilePath = '{}/{}'.format(baseDir, seed_file)
seed = wallet_name + '0'*(32 - len(wallet_name))
# if seed file is available, read seed from it
if os.path.isfile(seedFilePath):
with open(seedFilePath, mode='r+') as file:
seed = file.read().strip(' \t\n\r')
wallet = Wallet(wallet_name)
seed = bytes(seed, encoding='utf-8')
wallet.addIdentifier(signer=DidSigner(seed=seed))
return wallet
async def bootstrap_schema(agent, attrib_def_name, schema_name, schema_version, p_prime, q_prime):
schema_id = await agent.publish_schema(attrib_def_name,
schema_name=schema_name,
schema_version=schema_version)
_, _ = await agent.publish_issuer_keys(schema_id, p_prime=p_prime, q_prime=q_prime)
# TODO not fully implemented yet!
# await agent.publish_revocation_registry(schema_id=schema_id)
return schema_id
def buildAgentWallet(name, seed):
wallet = Wallet(name)
wallet.addIdentifier(signer=DidSigner(seed=seed))
return wallet