Skip to content

Commit

Permalink
feat: update to optional privacy sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
tammo committed Nov 2, 2020
1 parent 462f86e commit 19f9f44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/getNtruPublicKey.ts → src/getBlockchain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from 'axios';
import { SigPublicKey, NTRUPublicKey } from '@tixl/tixl-types';
import { SigPublicKey, Blockchain } from '@tixl/tixl-types';

const chainUrl = process.env.GATEWAY_URL + '/blockchain';

export default async function getNtruPublicKey(publicSig: SigPublicKey): Promise<NTRUPublicKey | undefined> {
export default async function getBlockchain(publicSig: SigPublicKey): Promise<Blockchain | undefined> {
return axios
.get(chainUrl + `?full=false&signaturePublicKey=${publicSig}`)
.then(res => {
if (res.data.blockchain) {
return res.data.blockchain.publicNtru;
return res.data.blockchain;
}
})
.catch(err => {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { canUserReceive, updateOrCreateUserTimestamp } = require('./fauna');
import eh from 'hash-emoji';
import { log, configureLogger } from './logger';
import { startLifeSignal } from './lifeSignal';
import getNtruPublicKey from './getNtruPublicKey';
import getBlockchain from './getBlockchain';
import { queue } from './sendFromGenesis';

if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'local_with_logger') {
Expand Down Expand Up @@ -46,9 +46,9 @@ bot.on('text', async (ctx: any) => {
parse_mode: 'Markdown',
});

const ntruPublicKey = await getNtruPublicKey(address);
const chainTest = await getBlockchain(address);

if (!ntruPublicKey) {
if (!chainTest) {
log.info('Public signature key has no corresponding blockchain');
ctx.reply(`There does not seem to be a blockchain for this address.`);
return;
Expand All @@ -62,7 +62,7 @@ bot.on('text', async (ctx: any) => {
}

process.nextTick(async () => {
const { sendAmount, signature } = await sendFromGenesis(ntruPublicKey);
const { sendAmount, signature } = await sendFromGenesis(address);
const txlAmount = sendAmount / BigInt(Math.pow(10, 7));

log.info('created send block', { amount: String(sendAmount), signature });
Expand Down
7 changes: 1 addition & 6 deletions src/sendFromGenesis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Queue from 'promise-queue';
import { AssetSymbol, Block, Signature } from '@tixl/tixl-types';
import { decryptSender, decryptReceiver } from '@tixl/tixl-sdk-js/workflows/api/encryption';
import { createSendBlock } from '@tixl/tixl-sdk-js/workflows/api/send';

import { crypto } from './crypto';
Expand All @@ -20,9 +19,6 @@ export const sendFromGenesis = async (address: string): Promise<{ sendAmount: bi

if (!genChain || !genLeaf) throw 'no genesis chain found';

await decryptSender(crypto, genLeaf, process.env.GEN_AES || '', { forceDecryptBF: true });
await decryptReceiver(crypto, genLeaf, process.env.GEN_NTRU_PRIV || '');

const baseAmount = Math.floor(Math.random() * 5000000) + 1; // rng between 1..5,000,000
let rndTxl = baseAmount;
if (Math.random() > 0.9) {
Expand All @@ -45,10 +41,9 @@ export const sendFromGenesis = async (address: string): Promise<{ sendAmount: bi
genChain.publicSig,
sendAmount,
newGenBalance,
address,
AssetSymbol.TXL,
process.env.GEN_SIG_PRIV,
address,
process.env.GEN_AES,
);

// send tx to gateway
Expand Down

0 comments on commit 19f9f44

Please sign in to comment.