This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from near/feat-2fa
Feature: Add 2FA Support to CLI
- Loading branch information
Showing
4 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |