@haechi-labs/face-types
Advanced tools
Comparing version 1.2.0 to 1.2.1
export declare enum Network { | ||
ETHEREUM = "ethereum", | ||
/** @deprecated NETWORK */ | ||
ROPSTEN = "ropsten", | ||
GOERLI = "goerli", | ||
POLYGON = "polygon", | ||
@@ -10,2 +12,4 @@ MUMBAI = "mumbai", | ||
BAOBAB = "baobab", | ||
SOLANA = "solana", | ||
SOLANA_DEVNET = "solana_devnet", | ||
/** @deprecated use ETHEREUM */ | ||
@@ -28,2 +32,3 @@ ETH_MAINNET = "ethereum", | ||
} | ||
export declare const isSupportedNetwork: (network?: Network) => boolean; | ||
export declare const NetworkChainIdMap: { | ||
@@ -36,3 +41,6 @@ [key in Network | number]: Network | number; | ||
BNB_SMART_CHAIN = "BNB_SMART_CHAIN", | ||
KLAYTN = "KLAYTN" | ||
KLAYTN = "KLAYTN", | ||
SOLANA = "SOLANA" | ||
} | ||
export declare function isEthlikeBlockchain(blockchain: Blockchain): boolean; | ||
//# sourceMappingURL=blockchain.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Blockchain = exports.NetworkChainIdMap = exports.Network = void 0; | ||
exports.isEthlikeBlockchain = exports.Blockchain = exports.NetworkChainIdMap = exports.isSupportedNetwork = exports.Network = void 0; | ||
var Network; | ||
(function (Network) { | ||
Network["ETHEREUM"] = "ethereum"; | ||
/** @deprecated NETWORK */ | ||
Network["ROPSTEN"] = "ropsten"; | ||
Network["GOERLI"] = "goerli"; | ||
Network["POLYGON"] = "polygon"; | ||
@@ -14,2 +16,4 @@ Network["MUMBAI"] = "mumbai"; | ||
Network["BAOBAB"] = "baobab"; | ||
Network["SOLANA"] = "solana"; | ||
Network["SOLANA_DEVNET"] = "solana_devnet"; | ||
/** @deprecated use ETHEREUM */ | ||
@@ -32,5 +36,24 @@ Network["ETH_MAINNET"] = "ethereum"; | ||
})(Network = exports.Network || (exports.Network = {})); | ||
const isSupportedNetwork = (network) => { | ||
switch (network) { | ||
case Network.ETHEREUM: | ||
case Network.GOERLI: | ||
case Network.POLYGON: | ||
case Network.MUMBAI: | ||
case Network.BNB_SMART_CHAIN: | ||
case Network.BNB_SMART_CHAIN_TESTNET: | ||
case Network.KLAYTN: | ||
case Network.BAOBAB: | ||
case Network.SOLANA: | ||
case Network.SOLANA_DEVNET: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}; | ||
exports.isSupportedNetwork = isSupportedNetwork; | ||
exports.NetworkChainIdMap = { | ||
[Network.ETHEREUM]: 1, | ||
[Network.ROPSTEN]: 3, | ||
[Network.GOERLI]: 5, | ||
[Network.POLYGON]: 137, | ||
@@ -42,4 +65,7 @@ [Network.MUMBAI]: 80001, | ||
[Network.BAOBAB]: 1001, | ||
[Network.SOLANA]: 0, | ||
[Network.SOLANA_DEVNET]: 0, | ||
1: Network.ETHEREUM, | ||
3: Network.ROPSTEN, | ||
5: Network.GOERLI, | ||
137: Network.POLYGON, | ||
@@ -58,3 +84,14 @@ 80001: Network.MUMBAI, | ||
Blockchain["KLAYTN"] = "KLAYTN"; | ||
Blockchain["SOLANA"] = "SOLANA"; | ||
})(Blockchain = exports.Blockchain || (exports.Blockchain = {})); | ||
const EthLikeBlockchains = [ | ||
Blockchain.ETHEREUM, | ||
Blockchain.POLYGON, | ||
Blockchain.BNB_SMART_CHAIN, | ||
Blockchain.KLAYTN, | ||
]; | ||
function isEthlikeBlockchain(blockchain) { | ||
return EthLikeBlockchains.indexOf(blockchain) !== -1; | ||
} | ||
exports.isEthlikeBlockchain = isEthlikeBlockchain; | ||
//# sourceMappingURL=blockchain.js.map |
@@ -31,1 +31,2 @@ import { BigNumber } from 'ethers'; | ||
} | ||
//# sourceMappingURL=crypto.d.ts.map |
export declare type Coin = 'ETH' | 'MATIC'; | ||
export declare type Token = 'USDT'; | ||
export declare type Currency = Coin | Token; | ||
//# sourceMappingURL=currency.d.ts.map |
@@ -9,1 +9,2 @@ export declare enum Env { | ||
} | ||
//# sourceMappingURL=env.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import { JsonRpcError, RpcErrorCode } from './json-rpc'; | ||
export declare enum HttpStatus { | ||
@@ -16,2 +17,3 @@ SUCCESS = 200, | ||
UNSUPPORTED_METHOD = 4200, | ||
UNSUPPORTED_CHAIN = 4201, | ||
DISCONNECTED = 4900, | ||
@@ -21,1 +23,28 @@ CHAIN_DISCONNECTED = 4901, | ||
} | ||
export declare class FaceError extends Error { | ||
private readonly code; | ||
data?: Record<string, any>; | ||
origin: any; | ||
private isValidErrorCode; | ||
constructor(error: { | ||
message: string; | ||
code: FaceErrorCode | RpcErrorCode; | ||
origin?: any; | ||
data?: Record<string, any>; | ||
}); | ||
} | ||
export declare function jsonRpcError(err: JsonRpcError): FaceError; | ||
export declare function faceServerError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function nitroEnclaveError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function firebaseError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function invalidEnvironmentError(data?: Record<string, any>): FaceError; | ||
export declare function cryptoError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function invalidFormatError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function invalidParameterError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function localStorageError(message: string, origin?: any, data?: Record<string, any>): FaceError; | ||
export declare function notImplementedError(message: string): FaceError; | ||
export declare function unknownError(origin?: any): FaceError; | ||
export declare function invalidApiKeyError(origin?: any): FaceError; | ||
export declare function invalidHostNameError(origin?: any): FaceError; | ||
export declare function unsupportedChainError(): FaceError; | ||
//# sourceMappingURL=error.d.ts.map |
138
lib/error.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FaceErrorCode = exports.HttpStatus = void 0; | ||
exports.unsupportedChainError = exports.invalidHostNameError = exports.invalidApiKeyError = exports.unknownError = exports.notImplementedError = exports.localStorageError = exports.invalidParameterError = exports.invalidFormatError = exports.cryptoError = exports.invalidEnvironmentError = exports.firebaseError = exports.nitroEnclaveError = exports.faceServerError = exports.jsonRpcError = exports.FaceError = exports.FaceErrorCode = exports.HttpStatus = void 0; | ||
const typeGuards_1 = require("./utils/typeGuards"); | ||
var HttpStatus; | ||
@@ -21,2 +22,3 @@ (function (HttpStatus) { | ||
FaceErrorCode[FaceErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD"; | ||
FaceErrorCode[FaceErrorCode["UNSUPPORTED_CHAIN"] = 4201] = "UNSUPPORTED_CHAIN"; | ||
FaceErrorCode[FaceErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED"; | ||
@@ -26,2 +28,136 @@ FaceErrorCode[FaceErrorCode["CHAIN_DISCONNECTED"] = 4901] = "CHAIN_DISCONNECTED"; | ||
})(FaceErrorCode = exports.FaceErrorCode || (exports.FaceErrorCode = {})); | ||
class FaceError extends Error { | ||
constructor(error) { | ||
super(); | ||
this.code = this.isValidErrorCode(error.code) ? error.code : FaceErrorCode.INTERNAL; | ||
this.message = `Face Error: [${this.code}] ${error.message}`; | ||
this.origin = error.origin; | ||
this.data = error.data; | ||
Object.setPrototypeOf(this, FaceError.prototype); | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
isValidErrorCode(code) { | ||
return (0, typeGuards_1.isJsonRpcErrorCode)(code) || (0, typeGuards_1.isFaceErrorCode)(code); | ||
} | ||
} | ||
exports.FaceError = FaceError; | ||
// --- face error factories | ||
function jsonRpcError(err) { | ||
return new FaceError({ | ||
message: err.message, | ||
code: err.code, | ||
data: err.data, | ||
}); | ||
} | ||
exports.jsonRpcError = jsonRpcError; | ||
function faceServerError(message, origin, data) { | ||
return new FaceError({ | ||
message: `face server error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.faceServerError = faceServerError; | ||
function nitroEnclaveError(message, origin, data) { | ||
return new FaceError({ | ||
message: `nitro enclave error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.nitroEnclaveError = nitroEnclaveError; | ||
function firebaseError(message, origin, data) { | ||
return new FaceError({ | ||
message: `firebase error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.firebaseError = firebaseError; | ||
function invalidEnvironmentError(data) { | ||
return new FaceError({ | ||
message: 'invalid environment', | ||
code: FaceErrorCode.INTERNAL, | ||
data, | ||
}); | ||
} | ||
exports.invalidEnvironmentError = invalidEnvironmentError; | ||
function cryptoError(message, origin, data) { | ||
return new FaceError({ | ||
message: `crypto error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.cryptoError = cryptoError; | ||
function invalidFormatError(message, origin, data) { | ||
return new FaceError({ | ||
message: `invalid format error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.invalidFormatError = invalidFormatError; | ||
function invalidParameterError(message, origin, data) { | ||
return new FaceError({ | ||
message: `invalid params error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.invalidParameterError = invalidParameterError; | ||
function localStorageError(message, origin, data) { | ||
return new FaceError({ | ||
message: `local storage error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
exports.localStorageError = localStorageError; | ||
function notImplementedError(message) { | ||
return new FaceError({ | ||
message, | ||
code: FaceErrorCode.NOT_IMPLEMENTED, | ||
}); | ||
} | ||
exports.notImplementedError = notImplementedError; | ||
function unknownError(origin) { | ||
return new FaceError({ | ||
message: 'unknown error', | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
}); | ||
} | ||
exports.unknownError = unknownError; | ||
function invalidApiKeyError(origin) { | ||
return new FaceError({ | ||
message: `invalid api key error`, | ||
code: FaceErrorCode.UNAUTHORIZED, | ||
origin, | ||
}); | ||
} | ||
exports.invalidApiKeyError = invalidApiKeyError; | ||
function invalidHostNameError(origin) { | ||
return new FaceError({ | ||
message: `invalid host name error`, | ||
code: FaceErrorCode.UNAUTHORIZED, | ||
origin, | ||
}); | ||
} | ||
exports.invalidHostNameError = invalidHostNameError; | ||
function unsupportedChainError() { | ||
return new FaceError({ | ||
message: `unsupported chain error`, | ||
code: FaceErrorCode.UNSUPPORTED_CHAIN, | ||
origin, | ||
}); | ||
} | ||
exports.unsupportedChainError = unsupportedChainError; | ||
//# sourceMappingURL=error.js.map |
import { BigNumber, BigNumberish } from 'ethers'; | ||
export interface FaceTransactionPayload { | ||
export declare type FaceTransactionPayload = FaceEthereumTransactionPayload | FaceSolanaTransactionPayload; | ||
export interface FaceEthereumTransactionPayload { | ||
from: string; | ||
@@ -9,2 +10,5 @@ to: string; | ||
} | ||
export interface FaceSolanaTransactionPayload { | ||
serializedHex: string; | ||
} | ||
export interface FaceLoginResponse { | ||
@@ -14,1 +18,2 @@ faceUserId: string; | ||
export declare type AccountsResponse = string[]; | ||
//# sourceMappingURL=face-event.d.ts.map |
@@ -10,1 +10,2 @@ export * from './blockchain'; | ||
export * from './user'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,3 +17,4 @@ export declare enum JsonRpcMethod { | ||
personal_sign = "personal_sign", | ||
wallet_switchEthereumChain = "wallet_switchEthereumChain" | ||
wallet_switchEthereumChain = "wallet_switchEthereumChain", | ||
solana_sendTransaction = "solana_sendTransaction" | ||
} | ||
@@ -60,1 +61,2 @@ export declare enum JsonRpcSource { | ||
} | ||
//# sourceMappingURL=json-rpc.d.ts.map |
@@ -22,2 +22,3 @@ "use strict"; | ||
JsonRpcMethod["wallet_switchEthereumChain"] = "wallet_switchEthereumChain"; | ||
JsonRpcMethod["solana_sendTransaction"] = "solana_sendTransaction"; | ||
})(JsonRpcMethod = exports.JsonRpcMethod || (exports.JsonRpcMethod = {})); | ||
@@ -24,0 +25,0 @@ var JsonRpcSource; |
@@ -7,1 +7,2 @@ export declare enum TxType { | ||
} | ||
//# sourceMappingURL=transaction.d.ts.map |
@@ -19,1 +19,2 @@ import { CryptoBuffer } from './crypto'; | ||
} | ||
//# sourceMappingURL=user.d.ts.map |
{ | ||
"name": "@haechi-labs/face-types", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "", | ||
@@ -25,3 +25,3 @@ "author": "", | ||
}, | ||
"gitHead": "e2252d25c71a6f76c64fdc81951c97ff7bd7407d", | ||
"gitHead": "77355be5218d5d6eb887ad4ea984ce347d12e451", | ||
"publishConfig": { | ||
@@ -28,0 +28,0 @@ "access": "public" |
export enum Network { | ||
ETHEREUM = 'ethereum', | ||
/** @deprecated NETWORK */ | ||
ROPSTEN = 'ropsten', | ||
GOERLI = 'goerli', | ||
POLYGON = 'polygon', | ||
@@ -10,2 +12,4 @@ MUMBAI = 'mumbai', | ||
BAOBAB = 'baobab', | ||
SOLANA = 'solana', | ||
SOLANA_DEVNET = 'solana_devnet', | ||
/** @deprecated use ETHEREUM */ | ||
@@ -29,5 +33,24 @@ ETH_MAINNET = 'ethereum', | ||
export const isSupportedNetwork = (network?: Network) => { | ||
switch (network) { | ||
case Network.ETHEREUM: | ||
case Network.GOERLI: | ||
case Network.POLYGON: | ||
case Network.MUMBAI: | ||
case Network.BNB_SMART_CHAIN: | ||
case Network.BNB_SMART_CHAIN_TESTNET: | ||
case Network.KLAYTN: | ||
case Network.BAOBAB: | ||
case Network.SOLANA: | ||
case Network.SOLANA_DEVNET: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}; | ||
export const NetworkChainIdMap: { [key in Network | number]: Network | number } = { | ||
[Network.ETHEREUM]: 1, | ||
[Network.ROPSTEN]: 3, | ||
[Network.GOERLI]: 5, | ||
[Network.POLYGON]: 137, | ||
@@ -39,5 +62,8 @@ [Network.MUMBAI]: 80001, | ||
[Network.BAOBAB]: 1001, | ||
[Network.SOLANA]: 0, | ||
[Network.SOLANA_DEVNET]: 0, | ||
1: Network.ETHEREUM, | ||
3: Network.ROPSTEN, | ||
5: Network.GOERLI, | ||
137: Network.POLYGON, | ||
@@ -56,2 +82,14 @@ 80001: Network.MUMBAI, | ||
KLAYTN = 'KLAYTN', | ||
SOLANA = 'SOLANA', | ||
} | ||
const EthLikeBlockchains = [ | ||
Blockchain.ETHEREUM, | ||
Blockchain.POLYGON, | ||
Blockchain.BNB_SMART_CHAIN, | ||
Blockchain.KLAYTN, | ||
]; | ||
export function isEthlikeBlockchain(blockchain: Blockchain): boolean { | ||
return EthLikeBlockchains.indexOf(blockchain) !== -1; | ||
} |
150
src/error.ts
@@ -0,1 +1,4 @@ | ||
import { JsonRpcError, RpcErrorCode } from './json-rpc'; | ||
import { isFaceErrorCode, isJsonRpcErrorCode } from './utils/typeGuards'; | ||
export enum HttpStatus { | ||
@@ -17,2 +20,3 @@ SUCCESS = 200, | ||
UNSUPPORTED_METHOD = 4200, | ||
UNSUPPORTED_CHAIN = 4201, | ||
DISCONNECTED = 4900, | ||
@@ -23,1 +27,147 @@ CHAIN_DISCONNECTED = 4901, | ||
} | ||
export class FaceError extends Error { | ||
private readonly code: FaceErrorCode | RpcErrorCode | number; | ||
public data?: Record<string, any>; | ||
public origin: any; | ||
private isValidErrorCode(code: number): boolean { | ||
return isJsonRpcErrorCode(code) || isFaceErrorCode(code); | ||
} | ||
constructor(error: { | ||
message: string; | ||
code: FaceErrorCode | RpcErrorCode; | ||
origin?: any; | ||
data?: Record<string, any>; | ||
}) { | ||
super(); | ||
this.code = this.isValidErrorCode(error.code!) ? error.code! : FaceErrorCode.INTERNAL; | ||
this.message = `Face Error: [${this.code}] ${error.message}`; | ||
this.origin = error.origin; | ||
this.data = error.data; | ||
Object.setPrototypeOf(this, FaceError.prototype); | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
// --- face error factories | ||
export function jsonRpcError(err: JsonRpcError) { | ||
return new FaceError({ | ||
message: err.message, | ||
code: err.code!, | ||
data: err.data, | ||
}); | ||
} | ||
export function faceServerError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `face server error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function nitroEnclaveError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `nitro enclave error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function firebaseError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `firebase error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function invalidEnvironmentError(data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: 'invalid environment', | ||
code: FaceErrorCode.INTERNAL, | ||
data, | ||
}); | ||
} | ||
export function cryptoError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `crypto error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function invalidFormatError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `invalid format error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function invalidParameterError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `invalid params error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function localStorageError(message: string, origin?: any, data?: Record<string, any>) { | ||
return new FaceError({ | ||
message: `local storage error: ${message}`, | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
data, | ||
}); | ||
} | ||
export function notImplementedError(message: string) { | ||
return new FaceError({ | ||
message, | ||
code: FaceErrorCode.NOT_IMPLEMENTED, | ||
}); | ||
} | ||
export function unknownError(origin?: any) { | ||
return new FaceError({ | ||
message: 'unknown error', | ||
code: FaceErrorCode.INTERNAL, | ||
origin, | ||
}); | ||
} | ||
export function invalidApiKeyError(origin?: any) { | ||
return new FaceError({ | ||
message: `invalid api key error`, | ||
code: FaceErrorCode.UNAUTHORIZED, | ||
origin, | ||
}); | ||
} | ||
export function invalidHostNameError(origin?: any) { | ||
return new FaceError({ | ||
message: `invalid host name error`, | ||
code: FaceErrorCode.UNAUTHORIZED, | ||
origin, | ||
}); | ||
} | ||
export function unsupportedChainError() { | ||
return new FaceError({ | ||
message: `unsupported chain error`, | ||
code: FaceErrorCode.UNSUPPORTED_CHAIN, | ||
origin, | ||
}); | ||
} |
import { BigNumber, BigNumberish } from 'ethers'; | ||
export interface FaceTransactionPayload { | ||
export type FaceTransactionPayload = FaceEthereumTransactionPayload | FaceSolanaTransactionPayload; | ||
export interface FaceEthereumTransactionPayload { | ||
from: string; | ||
@@ -11,2 +13,6 @@ to: string; | ||
export interface FaceSolanaTransactionPayload { | ||
serializedHex: string; | ||
} | ||
export interface FaceLoginResponse { | ||
@@ -13,0 +19,0 @@ faceUserId: string; |
@@ -21,2 +21,4 @@ export enum JsonRpcMethod { | ||
wallet_switchEthereumChain = 'wallet_switchEthereumChain', | ||
solana_sendTransaction = 'solana_sendTransaction', | ||
} | ||
@@ -23,0 +25,0 @@ |
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
68905
57
1397