def test_valid_replacement(self): did = 'did:factom:f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' chain_id = 'f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' external_ids = [consts.IDENTITY_CHAIN_TAG, b'Test', b'v1'] key_pairs = [identitykeys.generate_key_pair() for _ in range(3)] public_keys = [pub.to_string() for _, pub in key_pairs] content = {'version': 1, 'keys': public_keys} identity = Identity(did, chain_id) identity.process_creation( entry_hash=b'\0' * 32, external_ids=external_ids, content=json.dumps(content, separators=(',', ':')).encode(), stage='factom', height=123456 ) _, old_pub = key_pairs[-1] signer_priv, signer_pub = key_pairs[-2] new_priv, new_pub = identitykeys.generate_key_pair() message = chain_id.encode() + old_pub.to_string().encode() + new_pub.to_string().encode() external_ids = [ b'ReplaceKey', old_pub.to_string().encode(), new_pub.to_string().encode(), signer_priv.sign(message), signer_pub.to_string().encode() ] result = identity.process_key_replacement(entry_hash=b'\0' * 32, external_ids=external_ids, height=123457) self.assertTrue(result)
def test_valid_input(self): did = 'did:factom:f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' chain_id = 'f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' external_ids = [consts.IDENTITY_CHAIN_TAG, b'Test', b'v1'] public_keys = [identitykeys.generate_key_pair()[1].to_string() for _ in range(3)] content = {'version': 1, 'keys': public_keys} identity = Identity(did, chain_id) identity.process_creation( entry_hash= b'\0' * 32, external_ids=external_ids, content=json.dumps(content, separators=(',', ':')).encode(), stage='factom', height=123456 ) self.assertEqual(1, identity.version) for i, external_id in enumerate(external_ids[1:]): self.assertEqual(external_id.decode(), identity.name[i]) for k in public_keys: self.assertIn(k, identity.active_keys) self.assertIn(k, identity.all_keys) for k in identity.active_keys.values(): self.assertIn('id', k) self.assertIn('controller', k) self.assertIn('type', k) self.assertIn('publicKeyHex', k) self.assertIn('activatedHeight', k) self.assertIn('retiredHeight', k) self.assertIn('priority', k) self.assertIn('entryHash', k)
def getKeys(): private_key, public_key = identitykeys.generate_key_pair() private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) sig = signature return public, sig
def test_bad_version(self): did = 'did:factom:f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' chain_id = 'f26e1c422c657521861ced450442d0c664702f49480aec67805822edfcfee758' external_ids = [consts.IDENTITY_CHAIN_TAG, b'Test', b'v1'] public_keys = [identitykeys.generate_key_pair()[1].to_string() for _ in range(3)] content = {'version': 'BAD', 'keys': public_keys} identity = Identity(did, chain_id) with self.assertRaises(IdentityNotFoundException): identity.process_creation( entry_hash=b'\0' * 32, external_ids=external_ids, content=json.dumps(content, separators=(',', ':')).encode(), stage='factom', height=123456 )
def factomizeTweets(tweetid, chainid, factomd, walletd): private_key, public_key = identitykeys.generate_key_pair( ) #generates a public, private key pare private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) sig = signature #base64 encoded pseudo signature fct_address = FCT_ADDRESS ec_address = EC_ADDRESS #initializes factomd --> host will need to be changed to your server address factomd = Factomd(host='http://YourHostAddress:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') #initializes walletd --> host will need to be changed to your server address walletd = FactomWalletd(host='http://YourHostAddress:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') try: status = api.get_status( int(tweetid )) #uses a tweet id to recreate an entire status/tweet object userid = status.user.id #gets the user or twitterid for the account user_id = str(userid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation tweetid = str(status.id) tweet_id = str(tweetid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation date = datetime.now() date2 = str(date).replace("'", '"') fct_entry = {"Date_Recorded": date2, "tweet": status._json} print('Sending Tweet to Factom!') tweet = fct_entry["tweet"] try: chain_id = str(chain_id) resp = walletd.new_entry( factomd, chain_id, ["TwitterBank Chain", user_id, tweet_id, public, sig], json.dumps(fct_entry), ec_address=ec_address) # makes entry into the factom testnet entryhash = resp['entryhash'] time.sleep(10) except exceptions.FactomAPIError as e: print(e.data) print('ERROR') return True except tweepy.TweepError: time.sleep(60 * 15) print('this messed up') #continue print('processing next tweet')
def factomizeTweets(tweetid, chain_id): private_key, public_key = identitykeys.generate_key_pair( ) #generates a public, private key pare private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) sig = signature #base64 encoded pseudo signature fct_address = FCT_ADDRESS ec_address = EC_ADDRESS #initializes factomd --> host will need to be changed to your server address factomd = Factomd(host='http://18.222.184.135:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') #initializes walletd --> host will need to be changed to your server address walletd = FactomWalletd(host='http://18.222.184.135:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') try: status = api.get_status( int(tweetid )) #uses a tweet id to recreate an entire status/tweet object userid = status.user.id #gets the user or twitterid for the account user_id = str(userid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation tweetid = str(status.id) tweet_id = str(tweetid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation #name = status.user.screen_name #pulls username of tweeter #print('@',name, 'tweeted', status.text) #prints tweet to terminal date = datetime.now() date2 = str(date).replace("'", '"') fct_entry = {"Date_Recorded": date2, "tweet": status._json} print('Sending Tweet to Factom!') tweet = fct_entry["tweet"] try: chain_id = str(chain_id) resp = walletd.new_entry( factomd, chain_id, ['TwitterBank Chain', user_id, tweet_id, public, sig], json.dumps(fct_entry), ec_address=ec_address) # makes entry into the factom testnet #print(' Tweet Successfully Entered Into the Factom Testnet!') print(resp) entryhash = resp['entryhash'] #print(entryhash) #producer.send_messages(str(UserDict[str(userid)]), entryhash.encode('utf-8')) time.sleep(10) #print('Tweet Processed! Waiting For More Tweets to Factomize...') except exceptions.FactomAPIError as e: print(e.data) print('ERROR') return True except tweepy.TweepError: time.sleep(60 * 15) print('this messed up') #continue print('processing next tweet')
from config import config conf = config[os.environ.get('SCRIBE_CONFIG', 'development')] factom_url = conf.FACTOM_BASE_URL wallet_url = conf.WALLET_BASE_URL ec_address = conf.EC_ADDR fct_address = conf.FC_ADDR TWITTER_KEY = conf.TWITTER_KEY TWITTER_SECRET = conf.TWITTER_SECRET TWITTER_APP_KEY = conf.TWITTER_APP_KEY TWITTER_APP_SECRET = conf.TWITTER_APP_SECRET from utils import filterTweets, getAllTweets, sendTweets, filterTweets, getAllTweets, fromCreator, getKeys, getTwitterCredentials, reconstructTweet private_key, public_key = identitykeys.generate_key_pair() private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) factomd = Factomd(host=factom_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') walletd = FactomWalletd(host=wallet_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******')