@haechi-labs/face-sdk
Advanced tools
Comparing version 0.1.2-alpha.0 to 0.1.2-alpha.1
@@ -7,3 +7,4 @@ import { FaceLoginResponse } from '@haechi-labs/face-types'; | ||
login(): Promise<FaceLoginResponse | null>; | ||
signOut(): Promise<void>; | ||
logout(): Promise<void>; | ||
isLoggedIn(): Promise<boolean>; | ||
} |
@@ -11,7 +11,10 @@ "use strict"; | ||
} | ||
async signOut() { | ||
await this.internal.signOut(); | ||
async logout() { | ||
await this.internal.logout(); | ||
} | ||
async isLoggedIn() { | ||
return await this.internal.isLoggedIn(); | ||
} | ||
} | ||
exports.Auth = Auth; | ||
//# sourceMappingURL=auth.js.map |
@@ -1,16 +0,25 @@ | ||
import { Blockchain, Env } from '@haechi-labs/face-types'; | ||
import { Auth } from './auth'; | ||
import { Provider } from './provider'; | ||
export declare enum Network { | ||
'ETHEREUM' = 0, | ||
'ROPSTEN' = 1 | ||
ETH_MAINNET = "ethereum", | ||
ETH_TESTNET = "ropsten", | ||
MATIC_MAINNET = "polygon", | ||
MATIC_TESTNET = "mumbai" | ||
} | ||
export interface Requirements { | ||
apiKey: string; | ||
network?: Network; | ||
} | ||
export declare class Face { | ||
private readonly internal; | ||
auth: Auth; | ||
constructor(network: Network, blockchain: Blockchain, apiKey: string, iframeUrl?: string, apiUrl?: string, env?: Env); | ||
/** | ||
* Add requirements. `args2` does not need if `args1` type is Requirements | ||
* @param {string? | Requirements?} args1 | ||
* @param {Network?} args2 | ||
*/ | ||
constructor(args1: string | Requirements, args2?: Network | any); | ||
ready(): Promise<void>; | ||
getEthLikeProvider(): Provider; | ||
getAddresses: () => Promise<string[]>; | ||
private getUser; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Face = exports.Network = void 0; | ||
const face_types_1 = require("@haechi-labs/face-types"); | ||
const auth_1 = require("./auth"); | ||
@@ -10,11 +9,35 @@ const internal_1 = require("./internal"); | ||
(function (Network) { | ||
Network[Network["ETHEREUM"] = 0] = "ETHEREUM"; | ||
Network[Network["ROPSTEN"] = 1] = "ROPSTEN"; | ||
Network["ETH_MAINNET"] = "ethereum"; | ||
Network["ETH_TESTNET"] = "ropsten"; | ||
Network["MATIC_MAINNET"] = "polygon"; | ||
Network["MATIC_TESTNET"] = "mumbai"; | ||
})(Network = exports.Network || (exports.Network = {})); | ||
class Face { | ||
constructor(network, blockchain, apiKey, iframeUrl, apiUrl, env) { | ||
// arguments[1] = apiKey | ||
// arguments[2] = network | ||
// arguments[3] = env | ||
// arguments[4] = iframeUrl | ||
/** | ||
* Add requirements. `args2` does not need if `args1` type is Requirements | ||
* @param {string? | Requirements?} args1 | ||
* @param {Network?} args2 | ||
*/ | ||
constructor(args1, args2) { | ||
this.getAddresses = async () => { | ||
return await this.internal.getAddresses(); | ||
}; | ||
this.internal = new internal_1.Internal(network, blockchain, apiKey, env !== null && env !== void 0 ? env : face_types_1.Env.ProdMainnet, iframeUrl, apiUrl); | ||
if (typeof args1 === 'string') { | ||
// eslint-disable-next-line prefer-rest-params | ||
this.internal = new internal_1.Internal(args1, args2, arguments[2], arguments[3]); | ||
} | ||
else if (typeof args1 === 'object') { | ||
this.internal = new internal_1.Internal(args1.apiKey, args1.network, args2, // env | ||
// eslint-disable-next-line prefer-rest-params | ||
arguments[2] | ||
// eslint-disable-next-line prefer-rest-params | ||
); | ||
} | ||
else { | ||
throw new Error('api key is not provided'); | ||
} | ||
this.auth = new auth_1.Auth(this.internal); | ||
@@ -28,5 +51,4 @@ } | ||
} | ||
async getUser() { } | ||
} | ||
exports.Face = Face; | ||
//# sourceMappingURL=face.js.map |
import { Blockchain, Env, FaceMessageRequest, FaceMessageResponse, FaceMessageType } from '@haechi-labs/face-types'; | ||
import { Network } from './face'; | ||
export declare class Iframe { | ||
private readonly _network; | ||
private readonly _blockchain; | ||
@@ -10,3 +8,3 @@ private readonly _iframe; | ||
private activeElement; | ||
constructor(network: Network, blockchain: Blockchain, env: Env, apiKey: string, iframeUrl?: string, apiUrl?: string); | ||
constructor(apiKey: string, blockchain: Blockchain, env: Env, iframeUrl: string); | ||
sendChildMessage(data: FaceMessageRequest): Promise<number>; | ||
@@ -13,0 +11,0 @@ waitForResponse<T>(types: FaceMessageType[], timestamp?: number): Promise<T>; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const face_types_1 = require("@haechi-labs/face-types"); | ||
const face_1 = require("./face"); | ||
const overlayStyles = { | ||
@@ -42,6 +41,5 @@ display: 'none', | ||
class Iframe { | ||
constructor(network, blockchain, env, apiKey, iframeUrl, apiUrl) { | ||
constructor(apiKey, blockchain, env, iframeUrl) { | ||
this._ready = new Ready(); | ||
this.activeElement = null; | ||
this._network = network; | ||
this._blockchain = blockchain; | ||
@@ -64,16 +62,3 @@ this._env = env; | ||
iframe.title = 'Secure Modal'; | ||
// TODO: We should change iframeUrl calculate code | ||
if (env === face_types_1.Env.ProdMainnet) { | ||
if (network === face_1.Network.ETHEREUM) { | ||
iframeUrl = iframeUrl || 'https://app.facewallet.xyz'; | ||
// FIXME | ||
apiUrl = "https://facewallet.xyz/api/v1"; | ||
} | ||
else { | ||
iframeUrl = iframeUrl || 'https://app.test.facewallet.xyz'; | ||
apiUrl = "https://test.facewallet.xyz/api/v1"; | ||
env = face_types_1.Env.ProdTest; | ||
} | ||
} | ||
iframe.src = new URL(`${iframeUrl !== null && iframeUrl !== void 0 ? iframeUrl : 'https://app.facewallet.xyz'}?api_key=${apiKey}&blockchain=${blockchain}&apiUrl=${apiUrl}&env=${env}`).href; | ||
iframe.src = new URL(`${iframeUrl}?api_key=${apiKey}&blockchain=${blockchain}&env=${env}`).href; | ||
iframe.allow = 'clipboard-write'; | ||
@@ -80,0 +65,0 @@ applyOverlayStyles(iframe); |
@@ -7,7 +7,8 @@ import { Blockchain, Env, FaceLoginResponse, FaceTransactionPayload, JsonRpcRequestPayload } from '@haechi-labs/face-types'; | ||
private readonly iframe; | ||
constructor(network: Network, blockchain: Blockchain, apiKey: string, env: Env, iframeUrl?: string, apiUrl?: string); | ||
constructor(apiKey: string, network?: Network, env?: Env, iframeUrl?: string); | ||
getAddresses(): Promise<string[]>; | ||
estimateGas(request: RequestArguments): Promise<unknown>; | ||
getBalance(address: string): Promise<BigNumber>; | ||
signOut(): Promise<void>; | ||
logout(): Promise<void>; | ||
isLoggedIn(): Promise<boolean>; | ||
ready(): Promise<void>; | ||
@@ -17,2 +18,5 @@ loginWithCredential(): Promise<FaceLoginResponse | null>; | ||
sendRpc<T>(rpcPayload: JsonRpcRequestPayload | JsonRpcRequestPayload[]): Promise<T>; | ||
getBlockchainFromNetwork(network?: Network): Blockchain; | ||
getIframeUrl(env?: Env, iframeUrl?: string): string; | ||
getDefaultEnv(network?: Network): Env; | ||
} |
@@ -6,6 +6,10 @@ "use strict"; | ||
const ethers_1 = require("ethers"); | ||
const face_1 = require("./face"); | ||
const iframe_1 = require("./iframe"); | ||
class Internal { | ||
constructor(network, blockchain, apiKey, env, iframeUrl, apiUrl) { | ||
this.iframe = new iframe_1.Iframe(network, blockchain, env, apiKey, iframeUrl, apiUrl); | ||
constructor(apiKey, network, env, iframeUrl) { | ||
const blockchain = this.getBlockchainFromNetwork(network); | ||
this.iframe = new iframe_1.Iframe(apiKey, blockchain, | ||
// TODO: env is not configured yet, so need to change as env configured | ||
env !== null && env !== void 0 ? env : this.getDefaultEnv(network), this.getIframeUrl(env, iframeUrl)); | ||
} | ||
@@ -41,10 +45,18 @@ async getAddresses() { | ||
} | ||
async signOut() { | ||
async logout() { | ||
await this.iframe.sendChildMessage({ | ||
type: face_types_1.FaceMessageType.FACE_SIGN_OUT, | ||
type: face_types_1.FaceMessageType.FACE_LOG_OUT, | ||
}); | ||
const result = await this.iframe.waitForResponse([ | ||
face_types_1.FaceMessageType.FACE_SIGN_OUT, | ||
]); | ||
await this.iframe.waitForResponse([face_types_1.FaceMessageType.FACE_LOG_OUT]); | ||
} | ||
async isLoggedIn() { | ||
await this.iframe.sendChildMessage({ | ||
type: face_types_1.FaceMessageType.FACE_LOGGED_IN, | ||
}); | ||
const response = await this.iframe.waitForResponse([face_types_1.FaceMessageType.FACE_LOGGED_IN]); | ||
if (response) { | ||
return response; | ||
} | ||
return false; | ||
} | ||
async ready() { | ||
@@ -96,4 +108,46 @@ return this.iframe.ready(); | ||
} | ||
getBlockchainFromNetwork(network) { | ||
switch (network) { | ||
case face_1.Network.ETH_MAINNET: | ||
case face_1.Network.ETH_TESTNET: | ||
return face_types_1.Blockchain.ETH; | ||
case face_1.Network.MATIC_MAINNET: | ||
case face_1.Network.MATIC_TESTNET: | ||
return face_types_1.Blockchain.MATIC; | ||
default: | ||
return face_types_1.Blockchain.ETH; | ||
} | ||
} | ||
getIframeUrl(env, iframeUrl) { | ||
if (iframeUrl != null) { | ||
return iframeUrl; | ||
} | ||
switch (env) { | ||
case face_types_1.Env.Local: | ||
return 'http://localhost:3333'; | ||
case face_types_1.Env.Dev: | ||
return 'https://app.dev.facewallet.xyz'; | ||
case face_types_1.Env.StageTest: | ||
return 'https://app.stage-test.facewallet.xyz'; | ||
case face_types_1.Env.ProdTest: | ||
return 'https://app.test.facewallet.xyz'; | ||
case face_types_1.Env.StageMainnet: | ||
return 'https://app.stage.facewallet.xyz'; | ||
case face_types_1.Env.ProdMainnet: | ||
return 'https://app.facewallet.xyz'; | ||
default: | ||
return 'https://app.facewallet.xyz'; | ||
} | ||
} | ||
getDefaultEnv(network) { | ||
if (!network) { | ||
return face_types_1.Env.ProdMainnet; | ||
} | ||
if (network === face_1.Network.ETH_TESTNET || network === face_1.Network.MATIC_TESTNET) { | ||
return face_types_1.Env.ProdTest; | ||
} | ||
return face_types_1.Env.ProdMainnet; | ||
} | ||
} | ||
exports.Internal = Internal; | ||
//# sourceMappingURL=internal.js.map |
{ | ||
"name": "@haechi-labs/face-sdk", | ||
"version": "0.1.2-alpha.0", | ||
"version": "0.1.2-alpha.1", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "author": "", | ||
"devDependencies": { | ||
"@haechi-labs/face-types": "^0.1.2-alpha.0", | ||
"@haechi-labs/face-types": "^0.1.2-alpha.1", | ||
"@tsconfig/node16": "^1.0.2", | ||
@@ -27,3 +27,3 @@ "@types/node": "^17.0.33", | ||
}, | ||
"gitHead": "09f2002d1a6e5bd5bcb303ff0d68dba713cf57a0", | ||
"gitHead": "192137846cc139b7c43ff1802b73daaf4ccf780f", | ||
"publishConfig": { | ||
@@ -30,0 +30,0 @@ "access": "public" |
@@ -16,5 +16,9 @@ import { FaceLoginResponse } from '@haechi-labs/face-types'; | ||
async signOut(): Promise<void> { | ||
await this.internal.signOut(); | ||
async logout(): Promise<void> { | ||
await this.internal.logout(); | ||
} | ||
async isLoggedIn(): Promise<boolean> { | ||
return await this.internal.isLoggedIn(); | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
import { Blockchain, Env } from '@haechi-labs/face-types'; | ||
import { Auth } from './auth'; | ||
@@ -8,6 +6,13 @@ import { Internal } from './internal'; | ||
export enum Network { | ||
'ETHEREUM', | ||
'ROPSTEN', | ||
ETH_MAINNET = 'ethereum', | ||
ETH_TESTNET = 'ropsten', | ||
MATIC_MAINNET = 'polygon', | ||
MATIC_TESTNET = 'mumbai', | ||
} | ||
export interface Requirements { | ||
apiKey: string; | ||
network?: Network; | ||
} | ||
export class Face { | ||
@@ -17,18 +22,27 @@ private readonly internal: Internal; | ||
constructor( | ||
network: Network, | ||
blockchain: Blockchain, | ||
apiKey: string, | ||
iframeUrl?: string, | ||
apiUrl?: string, | ||
env?: Env | ||
) { | ||
this.internal = new Internal( | ||
network, | ||
blockchain, | ||
apiKey, | ||
env ?? Env.ProdMainnet, | ||
iframeUrl, | ||
apiUrl | ||
); | ||
// arguments[1] = apiKey | ||
// arguments[2] = network | ||
// arguments[3] = env | ||
// arguments[4] = iframeUrl | ||
/** | ||
* Add requirements. `args2` does not need if `args1` type is Requirements | ||
* @param {string? | Requirements?} args1 | ||
* @param {Network?} args2 | ||
*/ | ||
constructor(args1: string | Requirements, args2?: Network | any) { | ||
if (typeof args1 === 'string') { | ||
// eslint-disable-next-line prefer-rest-params | ||
this.internal = new Internal(args1, args2, arguments[2], arguments[3]); | ||
} else if (typeof args1 === 'object') { | ||
this.internal = new Internal( | ||
args1.apiKey, | ||
args1.network, | ||
args2, // env | ||
// eslint-disable-next-line prefer-rest-params | ||
arguments[2] | ||
// eslint-disable-next-line prefer-rest-params | ||
); | ||
} else { | ||
throw new Error('api key is not provided'); | ||
} | ||
this.auth = new Auth(this.internal); | ||
@@ -48,4 +62,2 @@ } | ||
}; | ||
private async getUser(): Promise<void> {} | ||
} |
@@ -9,4 +9,2 @@ import { | ||
import { Network } from './face'; | ||
const overlayStyles: Partial<CSSStyleDeclaration> = { | ||
@@ -50,3 +48,2 @@ display: 'none', | ||
export class Iframe { | ||
private readonly _network: Network; | ||
private readonly _blockchain: Blockchain; | ||
@@ -59,11 +56,3 @@ private readonly _iframe!: Promise<HTMLIFrameElement>; | ||
constructor( | ||
network: Network, | ||
blockchain: Blockchain, | ||
env: Env, | ||
apiKey: string, | ||
iframeUrl?: string, | ||
apiUrl?: string | ||
) { | ||
this._network = network; | ||
constructor(apiKey: string, blockchain: Blockchain, env: Env, iframeUrl: string) { | ||
this._blockchain = blockchain; | ||
@@ -89,18 +78,4 @@ this._env = env; | ||
iframe.title = 'Secure Modal'; | ||
// TODO: We should change iframeUrl calculate code | ||
if (env === Env.ProdMainnet) { | ||
if (network === Network.ETHEREUM) { | ||
iframeUrl = iframeUrl || 'https://app.facewallet.xyz'; | ||
// FIXME | ||
apiUrl = "https://facewallet.xyz/api/v1"; | ||
} else { | ||
iframeUrl = iframeUrl || 'https://app.test.facewallet.xyz'; | ||
apiUrl = "https://test.facewallet.xyz/api/v1"; | ||
env = Env.ProdTest; | ||
} | ||
} | ||
iframe.src = new URL( | ||
`${ | ||
iframeUrl ?? 'https://app.facewallet.xyz' | ||
}?api_key=${apiKey}&blockchain=${blockchain}&apiUrl=${apiUrl}&env=${env}` | ||
`${iframeUrl}?api_key=${apiKey}&blockchain=${blockchain}&env=${env}` | ||
).href; | ||
@@ -107,0 +82,0 @@ iframe.allow = 'clipboard-write'; |
@@ -7,3 +7,2 @@ import { | ||
FaceTransactionPayload, | ||
JsonRpcError, | ||
JsonRpcRequestPayload, | ||
@@ -21,11 +20,11 @@ JsonRpcResponsePayload, | ||
constructor( | ||
network: Network, | ||
blockchain: Blockchain, | ||
apiKey: string, | ||
env: Env, | ||
iframeUrl?: string, | ||
apiUrl?: string | ||
) { | ||
this.iframe = new Iframe(network, blockchain, env, apiKey, iframeUrl, apiUrl); | ||
constructor(apiKey: string, network?: Network, env?: Env, iframeUrl?: string) { | ||
const blockchain = this.getBlockchainFromNetwork(network); | ||
this.iframe = new Iframe( | ||
apiKey, | ||
blockchain, | ||
// TODO: env is not configured yet, so need to change as env configured | ||
env ?? this.getDefaultEnv(network), | ||
this.getIframeUrl(env, iframeUrl) | ||
); | ||
} | ||
@@ -69,11 +68,20 @@ | ||
async signOut(): Promise<void> { | ||
async logout(): Promise<void> { | ||
await this.iframe.sendChildMessage({ | ||
type: FaceMessageType.FACE_SIGN_OUT, | ||
type: FaceMessageType.FACE_LOG_OUT, | ||
}); | ||
const result = await this.iframe.waitForResponse<FaceLoginResponse | null>([ | ||
FaceMessageType.FACE_SIGN_OUT, | ||
]); | ||
await this.iframe.waitForResponse<FaceLoginResponse | null>([FaceMessageType.FACE_LOG_OUT]); | ||
} | ||
async isLoggedIn(): Promise<boolean> { | ||
await this.iframe.sendChildMessage({ | ||
type: FaceMessageType.FACE_LOGGED_IN, | ||
}); | ||
const response = await this.iframe.waitForResponse<boolean>([FaceMessageType.FACE_LOGGED_IN]); | ||
if (response) { | ||
return response; | ||
} | ||
return false; | ||
} | ||
async ready(): Promise<void> { | ||
@@ -131,2 +139,47 @@ return this.iframe.ready(); | ||
} | ||
getBlockchainFromNetwork(network?: Network): Blockchain { | ||
switch (network) { | ||
case Network.ETH_MAINNET: | ||
case Network.ETH_TESTNET: | ||
return Blockchain.ETH; | ||
case Network.MATIC_MAINNET: | ||
case Network.MATIC_TESTNET: | ||
return Blockchain.MATIC; | ||
default: | ||
return Blockchain.ETH; | ||
} | ||
} | ||
getIframeUrl(env?: Env, iframeUrl?: string): string { | ||
if (iframeUrl != null) { | ||
return iframeUrl; | ||
} | ||
switch (env) { | ||
case Env.Local: | ||
return 'http://localhost:3333'; | ||
case Env.Dev: | ||
return 'https://app.dev.facewallet.xyz'; | ||
case Env.StageTest: | ||
return 'https://app.stage-test.facewallet.xyz'; | ||
case Env.ProdTest: | ||
return 'https://app.test.facewallet.xyz'; | ||
case Env.StageMainnet: | ||
return 'https://app.stage.facewallet.xyz'; | ||
case Env.ProdMainnet: | ||
return 'https://app.facewallet.xyz'; | ||
default: | ||
return 'https://app.facewallet.xyz'; | ||
} | ||
} | ||
getDefaultEnv(network?: Network): Env { | ||
if (!network) { | ||
return Env.ProdMainnet; | ||
} | ||
if (network === Network.ETH_TESTNET || network === Network.MATIC_TESTNET) { | ||
return Env.ProdTest; | ||
} | ||
return Env.ProdMainnet; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59624
1411