-
Notifications
You must be signed in to change notification settings - Fork 4
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 #10 from Akord-com/auth
create auth module & wrap auth functions there
- Loading branch information
Showing
6 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,11 +1,6 @@ | ||
import Akord from "../akord"; | ||
import { AkordWallet } from "@akord/crypto"; | ||
import ApiAuthenticator from "../api/akord/api-authenticator"; | ||
import Akord from "../index"; | ||
|
||
export async function initInstance(email: string, password: string) : Promise<Akord> { | ||
const apiAuthenticator = new ApiAuthenticator(); | ||
const jwtToken = await apiAuthenticator.getJWTToken(email, password); | ||
const userAttributes = await apiAuthenticator.getUserAttributes(email, password); | ||
const wallet = await AkordWallet.importFromEncBackupPhrase(password, userAttributes["custom:encBackupPhrase"]); | ||
const { wallet, jwtToken } = await Akord.auth.signIn(email, password); | ||
return new Akord(wallet, jwtToken, { debug: true }); | ||
} |
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
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,55 @@ | ||
import Akord from "./akord"; | ||
import { AkordWallet } from "@akord/crypto"; | ||
import ApiAuthenticator from "./api/akord/api-authenticator"; | ||
|
||
class Auth { | ||
apiAuthenticator: ApiAuthenticator; | ||
|
||
constructor() { | ||
this.apiAuthenticator = new ApiAuthenticator(); | ||
} | ||
|
||
/** | ||
* @param {string} email | ||
* @param {string} password | ||
* @returns Promise with Akord Client instance, JWT token & Akord Wallet | ||
*/ | ||
public signIn = async function (email: string, password: string): Promise<{ akord: Akord, wallet: AkordWallet, jwtToken: string }> { | ||
const jwtToken = await this.apiAuthenticator.getJWTToken(email, password); | ||
const userAttributes = await this.apiAuthenticator.getUserAttributes(email, password); | ||
const wallet = await AkordWallet.importFromEncBackupPhrase(password, userAttributes["custom:encBackupPhrase"]); | ||
return { wallet, jwtToken, akord: new Akord(wallet, jwtToken) }; | ||
}; | ||
|
||
/** | ||
* @param {string} email | ||
* @param {string} password | ||
* @param {any} clientMetadata JSON client metadata, ex: { clientType: "CLI" } | ||
* @returns Promise with Akord Wallet | ||
*/ | ||
public signUp = async function (email: string, password: string, clientMetadata: any = {}): Promise<AkordWallet> { | ||
const wallet = await AkordWallet.create(password); | ||
await this.apiAuthenticator.signUp(email, password, { | ||
email, | ||
"custom:encBackupPhrase": wallet.encBackupPhrase, | ||
"custom:publicKey": await wallet.publicKey(), | ||
"custom:publicSigningKey": await wallet.signingPublicKey(), | ||
"custom:mode": "dark", | ||
"custom:notifications": "true", | ||
}, clientMetadata); | ||
return wallet; | ||
}; | ||
|
||
/** | ||
* @param {string} email | ||
* @param {string} code | ||
* @returns | ||
*/ | ||
public verifyAccount = async function (email: string, code: string): Promise<void> { | ||
await this.apiAuthenticator.verifyAccount(email, code); | ||
}; | ||
}; | ||
|
||
export { | ||
Auth | ||
} |
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