@haechi-labs/face-sdk
Advanced tools
Comparing version 1.0.0 to 1.1.0-alpha.0
@@ -0,11 +1,7 @@ | ||
import { Network } from '@haechi-labs/face-types'; | ||
import { Auth } from './auth'; | ||
import { Provider } from './provider'; | ||
import { WalletConnect } from './walletConnect'; | ||
export declare enum Network { | ||
ETH_MAINNET = "ethereum", | ||
ETH_TESTNET = "ropsten", | ||
MATIC_MAINNET = "polygon", | ||
MATIC_TESTNET = "mumbai" | ||
} | ||
export interface Requirements { | ||
export { Network }; | ||
export interface FaceConfig { | ||
apiKey: string; | ||
@@ -16,13 +12,12 @@ network?: Network; | ||
private readonly internal; | ||
private readonly network; | ||
wc: WalletConnect; | ||
auth: Auth; | ||
/** | ||
* 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); | ||
constructor({ apiKey, network, ...rest }: FaceConfig); | ||
ready(): Promise<void>; | ||
getEthLikeProvider(): Provider; | ||
getAddresses: () => Promise<string[]>; | ||
getNetwork: () => Network; | ||
getChainId: () => Promise<number>; | ||
switchNetwork(network: Network | number): Promise<unknown>; | ||
} |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Face = exports.Network = void 0; | ||
const face_types_1 = require("@haechi-labs/face-types"); | ||
Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return face_types_1.Network; } }); | ||
const utils_1 = require("ethers/lib/utils"); | ||
const auth_1 = require("./auth"); | ||
@@ -8,37 +22,16 @@ const internal_1 = require("./internal"); | ||
const walletConnect_1 = require("./walletConnect"); | ||
var Network; | ||
(function (Network) { | ||
Network["ETH_MAINNET"] = "ethereum"; | ||
Network["ETH_TESTNET"] = "ropsten"; | ||
Network["MATIC_MAINNET"] = "polygon"; | ||
Network["MATIC_TESTNET"] = "mumbai"; | ||
})(Network = exports.Network || (exports.Network = {})); | ||
class Face { | ||
// 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) { | ||
constructor(_a) { | ||
var { apiKey, network } = _a, rest = __rest(_a, ["apiKey", "network"]); | ||
this.getAddresses = async () => { | ||
return await this.internal.getAddresses(); | ||
}; | ||
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.getNetwork = () => { | ||
return this.network; | ||
}; | ||
this.getChainId = async () => { | ||
return Number(await this.internal.sendRpc({ method: 'eth_chainId', params: [] })); | ||
}; | ||
this.network = network || face_types_1.Network.ETH_MAINNET; | ||
this.internal = new internal_1.Internal(apiKey, network, rest.env, rest.iframeUrl); | ||
this.auth = new auth_1.Auth(this.internal); | ||
@@ -53,4 +46,11 @@ this.wc = new walletConnect_1.WalletConnect(this.internal); | ||
} | ||
async switchNetwork(network) { | ||
const chainId = typeof network === 'number' ? network : face_types_1.NetworkChainIdMap[network]; | ||
return this.internal.switchEthereumChain({ | ||
method: face_types_1.JsonRpcMethod.wallet_switchEthereumChain, | ||
params: [{ chainId: (0, utils_1.hexlify)(chainId) }], | ||
}); | ||
} | ||
} | ||
exports.Face = Face; | ||
//# sourceMappingURL=face.js.map |
import { Blockchain, Env, JsonRpcRequestPayload } from '@haechi-labs/face-types'; | ||
export declare class Iframe { | ||
private readonly _blockchain; | ||
private readonly _iframe; | ||
private readonly _env; | ||
private readonly _ready; | ||
private _blockchain; | ||
private randomPrefix; | ||
@@ -17,2 +17,3 @@ private requestIndex; | ||
hideOverlay(): Promise<void>; | ||
setBlockchain(blockchain: Blockchain): void; | ||
} |
@@ -149,4 +149,7 @@ "use strict"; | ||
} | ||
setBlockchain(blockchain) { | ||
this._blockchain = blockchain; | ||
} | ||
} | ||
exports.Iframe = Iframe; | ||
//# sourceMappingURL=iframe.js.map |
@@ -26,2 +26,3 @@ import { Blockchain, Env, FaceLoginResponse, JsonRpcRequestPayload, JsonRpcResponsePayload } from '@haechi-labs/face-types'; | ||
encodeData(abi: string[], functionFragment: string, args?: any[]): Promise<string>; | ||
switchEthereumChain(request: JsonRpcRequestPayload): Promise<unknown>; | ||
} |
@@ -137,2 +137,8 @@ "use strict"; | ||
return face_types_1.Blockchain.POLYGON; | ||
case face_1.Network.BINANCE_COIN_MAINNET: | ||
case face_1.Network.BINANCE_COIN_TESTNET: | ||
return face_types_1.Blockchain.BNB_SMART_CHAIN; | ||
case face_1.Network.KLAYTN_MAINNET: | ||
case face_1.Network.KLAYTN_TESTNET: | ||
return face_types_1.Blockchain.KLAYTN; | ||
default: | ||
@@ -167,3 +173,6 @@ return face_types_1.Blockchain.ETHEREUM; | ||
} | ||
if (network === face_1.Network.ETH_TESTNET || network === face_1.Network.MATIC_TESTNET) { | ||
if (network === face_1.Network.ETH_TESTNET || | ||
network === face_1.Network.MATIC_TESTNET || | ||
network === face_1.Network.KLAYTN_TESTNET || | ||
network === face_1.Network.BINANCE_COIN_TESTNET) { | ||
return face_types_1.Env.ProdTest; | ||
@@ -182,4 +191,11 @@ } | ||
} | ||
async switchEthereumChain(request) { | ||
const blockchain = this.getBlockchainFromNetwork(face_types_1.NetworkChainIdMap[Number(request.params[0].chainId)]); | ||
request.params[0].blockchain = blockchain; | ||
const res = await this.sendRpc(request); | ||
this.iframe.setBlockchain(blockchain); | ||
return res; | ||
} | ||
} | ||
exports.Internal = Internal; | ||
//# sourceMappingURL=internal.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Provider = void 0; | ||
const face_types_1 = require("@haechi-labs/face-types"); | ||
class ProviderTemplate { | ||
@@ -19,3 +20,5 @@ constructor() { | ||
switch (request.method) { | ||
case 'eth_estimateGas': | ||
case face_types_1.JsonRpcMethod.wallet_switchEthereumChain: | ||
return this.internal.switchEthereumChain(request); | ||
case face_types_1.JsonRpcMethod.eth_estimateGas: | ||
return this.internal.estimateGas(request); | ||
@@ -22,0 +25,0 @@ case 'personal_listAccounts': |
{ | ||
"name": "@haechi-labs/face-sdk", | ||
"version": "1.0.0", | ||
"version": "1.1.0-alpha.0", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "author": "", | ||
"devDependencies": { | ||
"@haechi-labs/face-types": "^1.0.0", | ||
"@haechi-labs/face-types": "^1.1.0-alpha.0", | ||
"@tsconfig/node16": "^1.0.2", | ||
@@ -27,3 +27,3 @@ "@types/node": "^17.0.33", | ||
}, | ||
"gitHead": "9fd9aaa5ac4702686815a6e9a8909022a48914e8", | ||
"gitHead": "418023f9c9b0e55af54cdc3e9b67e52b70984769", | ||
"publishConfig": { | ||
@@ -30,0 +30,0 @@ "access": "public" |
@@ -0,1 +1,4 @@ | ||
import { Env, JsonRpcMethod, Network, NetworkChainIdMap } from '@haechi-labs/face-types'; | ||
import { hexlify } from 'ethers/lib/utils'; | ||
import { Auth } from './auth'; | ||
@@ -6,10 +9,5 @@ import { Internal } from './internal'; | ||
export enum Network { | ||
ETH_MAINNET = 'ethereum', | ||
ETH_TESTNET = 'ropsten', | ||
MATIC_MAINNET = 'polygon', | ||
MATIC_TESTNET = 'mumbai', | ||
} | ||
export { Network }; | ||
export interface Requirements { | ||
export interface FaceConfig { | ||
apiKey: string; | ||
@@ -21,30 +19,14 @@ network?: Network; | ||
private readonly internal: Internal; | ||
private readonly network: Network; | ||
public wc: WalletConnect; | ||
public auth: Auth; | ||
// 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'); | ||
} | ||
constructor({ apiKey, network, ...rest }: FaceConfig) { | ||
this.network = network || Network.ETH_MAINNET; | ||
this.internal = new Internal( | ||
apiKey, | ||
network, | ||
(rest as { env?: Env }).env, | ||
(rest as { iframeUrl?: string }).iframeUrl | ||
); | ||
this.auth = new Auth(this.internal); | ||
@@ -65,2 +47,18 @@ this.wc = new WalletConnect(this.internal); | ||
}; | ||
getNetwork = (): Network => { | ||
return this.network; | ||
}; | ||
getChainId = async (): Promise<number> => { | ||
return Number(await this.internal.sendRpc({ method: 'eth_chainId', params: [] })); | ||
}; | ||
async switchNetwork(network: Network | number) { | ||
const chainId = typeof network === 'number' ? network : NetworkChainIdMap[network]; | ||
return this.internal.switchEthereumChain({ | ||
method: JsonRpcMethod.wallet_switchEthereumChain, | ||
params: [{ chainId: hexlify(chainId) }], | ||
}); | ||
} | ||
} |
@@ -47,6 +47,6 @@ import { | ||
export class Iframe { | ||
private readonly _blockchain: Blockchain; | ||
private readonly _iframe!: Promise<HTMLIFrameElement>; | ||
private readonly _env: Env; | ||
private readonly _ready = new Ready(); | ||
private _blockchain: Blockchain; | ||
private randomPrefix: string; | ||
@@ -174,7 +174,5 @@ private requestIndex = 0; | ||
// private waitForReady() { | ||
// return new Promise<void>((resolve) => { | ||
// this.on(MagicIncomingWindowMessage.MAGIC_OVERLAY_READY, () => resolve()); | ||
// }); | ||
// } | ||
setBlockchain(blockchain: Blockchain) { | ||
this._blockchain = blockchain; | ||
} | ||
} |
@@ -8,2 +8,3 @@ import { | ||
JsonRpcResponsePayload, | ||
NetworkChainIdMap, | ||
} from '@haechi-labs/face-types'; | ||
@@ -184,2 +185,8 @@ import { BigNumber, ethers } from 'ethers'; | ||
return Blockchain.POLYGON; | ||
case Network.BINANCE_COIN_MAINNET: | ||
case Network.BINANCE_COIN_TESTNET: | ||
return Blockchain.BNB_SMART_CHAIN; | ||
case Network.KLAYTN_MAINNET: | ||
case Network.KLAYTN_TESTNET: | ||
return Blockchain.KLAYTN; | ||
default: | ||
@@ -216,3 +223,8 @@ return Blockchain.ETHEREUM; | ||
} | ||
if (network === Network.ETH_TESTNET || network === Network.MATIC_TESTNET) { | ||
if ( | ||
network === Network.ETH_TESTNET || | ||
network === Network.MATIC_TESTNET || | ||
network === Network.KLAYTN_TESTNET || | ||
network === Network.BINANCE_COIN_TESTNET | ||
) { | ||
return Env.ProdTest; | ||
@@ -234,2 +246,14 @@ } | ||
} | ||
async switchEthereumChain(request: JsonRpcRequestPayload) { | ||
const blockchain = this.getBlockchainFromNetwork( | ||
NetworkChainIdMap[Number(request.params[0].chainId)] as Network | ||
); | ||
request.params[0].blockchain = blockchain; | ||
const res = await this.sendRpc(request); | ||
this.iframe.setBlockchain(blockchain); | ||
return res; | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { JsonRpcResponsePayload } from '@haechi-labs/face-types'; | ||
import { JsonRpcMethod, JsonRpcResponsePayload } from '@haechi-labs/face-types'; | ||
@@ -32,3 +32,5 @@ import { Internal } from './internal'; | ||
switch (request.method) { | ||
case 'eth_estimateGas': | ||
case JsonRpcMethod.wallet_switchEthereumChain: | ||
return this.internal.switchEthereumChain(request); | ||
case JsonRpcMethod.eth_estimateGas: | ||
return this.internal.estimateGas(request); | ||
@@ -35,0 +37,0 @@ case 'personal_listAccounts': |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
54778
30
1090
2