Skip to content

Commit

Permalink
full 2fa support
Browse files Browse the repository at this point in the history
  • Loading branch information
H34D committed Nov 8, 2022
1 parent 4c6052d commit f5d6fe7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"doc": "ts-node ./src/doc.ts"
},
"dependencies": {
"@masa-finance/masa-sdk": "^0.2.6",
"@masa-finance/masa-sdk": "^0.3.0",
"@types/clear": "^0.1.2",
"@types/figlet": "^1.5.5",
"chalk": "~4.1.2",
Expand Down
12 changes: 6 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,29 @@ program
}

{
const twofa = program.command("2fa").description("2fa Commands");
const twofa = program.command("2fa").description("2FA Commands");

twofa
.command("info")
.description("Shows info about all 2fas")
.description("Shows info about all 2FAs")
.action(async () => await twofaInfo());

twofa
.command("list")
.description("Lists your 2fas")
.description("Lists your 2FAs")
.option("-a, --address <address>", "Address override")
.action(async ({ address }) => await twofaList(address));

twofa
.command("create")
.argument("<phone-number>", "The phone number to verify")
.description("Creates a 2fa Token")
.description("Creates a 2FA Token")
.action(async (phoneNumber: string) => await twofaCreate(phoneNumber));

twofa
.command("burn")
.argument("<2fa-id>", "ID of the 2fa to burn")
.description("Burns a 2fa")
.argument("<2fa-id>", "ID of the 2FA to burn")
.description("Burns a 2FA")
.action(async (twofaId) => await twofaBurn(twofaId));
}

Expand Down
27 changes: 26 additions & 1 deletion src/commands/2fa/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { masa } from "../../helpers/masa";
import * as readline from "readline";
import { stdin as input, stdout as output } from "process";

const read = (question: string): Promise<string> => {
const rl = readline.createInterface({ input, output });

return new Promise((resolve) => {
rl.question(question, (result) => {
rl.close();
return resolve(result);
});
});
};

export const create = async (phoneNumber: string) => {
await masa.twofa.create(phoneNumber);
if (await masa.session.checkLogin()) {
const address = await masa.config.wallet.getAddress();
console.log(`Creating 2FA for phone number: '${phoneNumber}'`);

const identityId = await masa.identity.load(address);
if (!identityId) return;

await masa.twofa.generate(phoneNumber);
const code = await read(
"The code that has been sent to your Phonenumber: "
);
await masa.twofa.create(phoneNumber, code);
}
};
4 changes: 2 additions & 2 deletions src/commands/2fa/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { masa } from "../../helpers/masa";
export const info = async () => {
const identityContracts = await masa.contracts.loadIdentityContracts();

console.log("Soulbound 2fa");
console.log("Soulbound 2FA");
console.log(`Contract Address: '${identityContracts.Soulbound2FA.address}'`);
console.log(
`Total 2fas: ${(
`Total 2FAs: ${(
await identityContracts.Soulbound2FA.totalSupply()
).toNumber()}`
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@
dependencies:
ethers "^5.6.9"

"@masa-finance/masa-sdk@^0.2.6":
version "0.2.6"
resolved "https://registry.yarnpkg.com/@masa-finance/masa-sdk/-/masa-sdk-0.2.6.tgz#aaa8dd7745a85fa1a357bf7b850888616313acc0"
integrity sha512-ogi/RFlqKWQk7zCPoZdSbIH1nDTFMvzcfKKXrglIiSha7Kdv6yh9oU17H7baAZq/5wUrpazzEY5nM53JQaEe6A==
"@masa-finance/masa-sdk@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@masa-finance/masa-sdk/-/masa-sdk-0.3.0.tgz#a36a119e9c9816e32a0a75fa34d0d878b87f79fb"
integrity sha512-d2fxOYvcZZFItjBxQ0WTPFcQp0TZvThcUxqnJnUh6ZYQX4QfOIoElLoxmwlLQrUhZoz4xYJEwKdOQBlm8ZPNqg==
dependencies:
"@masa-finance/masa-contracts-identity" "^0.4.2"
arweave "^1.11.6"
Expand Down

0 comments on commit f5d6fe7

Please sign in to comment.