Skip to content

Commit

Permalink
toggle2fa constants in the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Aug 22, 2021
1 parent fd1b762 commit 3b4ac14
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
6 changes: 3 additions & 3 deletions infrastructure/api-docs/blueprint/groups/transactions.apib
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ Enable or disable requirement for L1 signature for L2 transactions.
+ Attributes
+ enable: false (boolean, required)
+ accountId: {{accountId}} (number, required)
+ timestamp: 1629451646472 (number, required)
+ signature: TxEthSignature
+ timestamp: {{toggle2FATimestamp}} (number, required)
+ signature (Toggle2FAEthSignature, required)

+ Response 200 (application/json)
+ Attributes
+ request (Request, required)
+ status: success (string, required)
+ result (2FAResult, required{{isResultNullable}})
+ result (Toggle2FAResult, required{{isResultNullable}})
+ error (Error, required, nullable)
12 changes: 10 additions & 2 deletions infrastructure/api-docs/blueprint/types/transactions.apib
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,13 @@
- tx (Transaction.Incoming, required)
- signature (TxEthSignatureVariant, required)

## 2FAResult (object)
- success true (boolean, required)
## Toggle2FAEthereumSignature
- type: `EthereumSignature` (string, fixed)
- signature: `{{toggle2FASignature}}` (string, required)

## Toggle2FAEthSignature (enum)
- (Toggle2FAEthereumSignature)
- (EIP1271Signature)

## Toggle2FAResult (object)
- success: true (boolean, required)
10 changes: 9 additions & 1 deletion infrastructure/api-docs/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ interface Parameters {
l2Signature: string;
ethereumSignature: string;
nftId: number;
toggle2FASignature: string;
toggle2FATimestamp: number;
}

async function getHashesAndSignatures() {
Expand Down Expand Up @@ -128,6 +130,10 @@ async function getHashesAndSignatures() {
const state = await syncWallet.getAccountState();
const nftId = Object.values(state.verified.nfts)[0].id;

const toggle2FAObject = await syncWallet.getToggle2FA(false);
const toggle2FASignature = (toggle2FAObject.signature as zksync.types.TxEthSignature).signature;
const toggle2FATimestamp = toggle2FAObject.timestamp;

let result: Parameters = {
txHash,
txBatchHash,
Expand All @@ -136,7 +142,9 @@ async function getHashesAndSignatures() {
pubKey,
l2Signature,
ethereumSignature,
nftId
nftId,
toggle2FASignature,
toggle2FATimestamp
};
return result;
}
Expand Down
16 changes: 11 additions & 5 deletions sdk/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
Withdraw,
WithdrawNFT,
TokenRatio,
WeiRatio
WeiRatio,
Toggle2FARequest
} from './types';
import {
ERC20_APPROVE_TRESHOLD,
Expand Down Expand Up @@ -916,18 +917,23 @@ export class Wallet {
return changePubKeyTx;
}

async toggle2FA(enable: boolean): Promise<boolean> {
await this.setRequiredAccountIdFromServer('Toggle 2FA');
async getToggle2FA(enable: boolean): Promise<Toggle2FARequest> {
const accountId = await this.getAccountId();
const timestamp = new Date().getTime();
const signature = await this.getEthMessageSignature(getToggle2FAMessage(enable, timestamp));

return await this.provider.toggle2FA({
return {
accountId,
signature,
timestamp,
enable
});
};
}

async toggle2FA(enable: boolean): Promise<boolean> {
await this.setRequiredAccountIdFromServer('Toggle 2FA');

return await this.provider.toggle2FA(await this.getToggle2FA(enable));
}

async signSetSigningKey(changePubKey: {
Expand Down

0 comments on commit 3b4ac14

Please sign in to comment.