Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #535 from near/feat-2fa
Browse files Browse the repository at this point in the history
Feature: Add 2FA Support to CLI
  • Loading branch information
mattlockyer authored Oct 12, 2020
2 parents aba622f + e3b0117 commit 4807fbc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Binary file added bin/multisig.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ exports.viewAccount = async function (options) {
};

exports.deleteAccount = async function (options) {

console.log(
`Deleting account. Account id: ${options.accountId}, node: ${options.nodeUrl}, helper: ${options.helperUrl}, beneficiary: ${options.beneficiaryId}`);
const near = await connect(options);
Expand Down
24 changes: 24 additions & 0 deletions utils/2fa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

// const prompts = require('prompts');
const readline = require('readline');
const chalk = require('chalk');

const getCode = async(method) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const securityCode = await new Promise((res) => {
rl.question(chalk`{bold Enter security code sent to ${ method.kind.split('2fa-')[1] }: }`, (accountId) => res(accountId));
});
rl.close();
return securityCode;
};

const onResult = async(result) => {
console.log('Request confirmed with result:', result);
};

module.exports = {
options2fa: { getCode, onResult }
};
13 changes: 10 additions & 3 deletions utils/connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const { connect: nearConnect } = require('near-api-js');
const {
connect: nearConnect,
multisig: {
modIfMultisig,
}
} = require('near-api-js');
const { options2fa } = require('./2fa');

module.exports = async function connect({ keyStore, ...options }) {
// TODO: Avoid need to wrap in deps
return await nearConnect({ ...options, deps: { keyStore }});
const near = await nearConnect({ ...options, deps: { keyStore }});
modIfMultisig(near, options2fa);
return near;
};

0 comments on commit 4807fbc

Please sign in to comment.