Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update CustomAuth to latest version #2255

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/common-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@material-ui/styles": "^4.11.2",
"@types/react-scroll": "^1.8.2",
"@types/react-select": "^3.0.27",
"@types/react-select": "3.0.27",
"a11y-react-emoji": "^1.1.2",
"clsx": "^1.1.1",
"normalize.css": "^8.0.1",
Expand All @@ -27,7 +27,7 @@
"react-dropzone": "^11.2.4",
"react-router-dom": "^5.2.0",
"react-scroll": "^1.8.1",
"react-select": "^3.1.1",
"react-select": "3.1.1",
"react-spinners": "^0.9.0",
"reset-css": "^5.0.1",
"rollup-plugin-babel": "^4.4.0"
Expand Down
10 changes: 5 additions & 5 deletions packages/files-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"@sentry/react": "^5.28.0",
"@stripe/react-stripe-js": "^1.4.1",
"@stripe/stripe-js": "^1.18.0",
"@tkey/default": "5.1.0",
"@tkey/security-questions": "5.1.0",
"@tkey/web-storage": "5.1.0",
"@toruslabs/customauth": "7.0.2",
"@tkey/default": "7.0.0",
"@tkey/security-questions": "7.0.0",
"@tkey/web-storage": "7.0.0",
"@toruslabs/customauth": "11.0.0",
"@types/filesystem": "^0.0.32",
"@types/uuid": "^8.3.0",
"axios": "0.26.1",
Expand Down Expand Up @@ -106,4 +106,4 @@
"last 1 safari version"
]
}
}
}
43 changes: 22 additions & 21 deletions packages/files-ui/src/Contexts/ThresholdKeyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TKEY_STORE_KEY = "csf.tkeyStore"
const TORUS_USERINFO_KEY = "csf.userInfo"
const PASSWORD_QUESTION = "What is your password?"

export type ThresholdKeyContextStatus = "initializing"|"initialized"|"awaiting confirmation"|"logging in"|"done"
export type ThresholdKeyContextStatus = "initializing" | "initialized" | "awaiting confirmation" | "logging in" | "done"
export type BrowserShare = {
shareIndex: string
module: string
Expand All @@ -48,7 +48,7 @@ export type TThresholdKeyContext = {
hasPasswordShare: boolean
shouldInitializeAccount: boolean
pendingShareTransferRequests: ShareTransferRequest[]
login(loginType: IdentityProvider, tokenInfo?: {token: string; email: string}): Promise<void>
login(loginType: IdentityProvider, tokenInfo?: { token: string; email: string }): Promise<void>
resetIsNewDevice(): void
resetShouldInitialize(): void
addPasswordShare(password: string): Promise<void>
Expand Down Expand Up @@ -92,8 +92,7 @@ export type ShareTransferRequest = {
const ThresholdKeyContext = React.createContext<TThresholdKeyContext | undefined>(undefined)
const maintenanceMode = process.env.REACT_APP_MAINTENANCE_MODE === "true"

const getProviderSpecificParams = (loginType: LOGIN_TYPE):
{typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => {
const getProviderSpecificParams = (loginType: LOGIN_TYPE): { typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any } => {
switch (loginType) {
case "google": {
return {
Expand All @@ -102,7 +101,7 @@ const getProviderSpecificParams = (loginType: LOGIN_TYPE):
verifier: "chainsafe-uuid-testnet"
}
}
case "github":{
case "github": {
return {
typeOfLogin: loginType,
clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "",
Expand All @@ -112,7 +111,7 @@ const getProviderSpecificParams = (loginType: LOGIN_TYPE):
}
}
}
default:{
default: {
throw new Error(`${loginType} is unsupported`)
}
}
Expand Down Expand Up @@ -208,9 +207,10 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
// The user will be required to log in to the respective service
tkey = new ThresholdKey({
modules,
directParams: {
customAuthArgs: {
baseUrl: `${window.location.origin}/serviceworker`,
network: network,
networkUrl: network === "testnet" ? "https://nd-598-268-537.p2pify.com/9a34d9de132b22e6b71b52d3fde80ff1" : undefined,
enableLogging: enableLogging,
apiKey: apiKey
},
Expand Down Expand Up @@ -286,7 +286,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
useEffect(() => {
const loginWithThresholdKey = async () => {
if (!userInfo) return
const decodedIdToken = jwtDecode<{exp: number}>(userInfo.userInfo.idToken || "")
const decodedIdToken = jwtDecode<{ exp: number }>(userInfo.userInfo.idToken || "")
if (privateKey && dayjs.unix(decodedIdToken.exp).isAfter(dayjs())) {
const pubKey = EthCrypto.publicKeyByPrivateKey(privateKey)
setPublicKey(pubKey)
Expand All @@ -308,7 +308,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
console.log("logging in using tkey")
loginWithThresholdKey()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [privateKey])

// Share Transfer poller
Expand All @@ -333,7 +333,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
[]
)

if(pendingShareTransferRequests.length !== pendingRequests.length){
if (pendingShareTransferRequests.length !== pendingRequests.length) {
setPendingShareTransferRequests(pendingRequests)
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f

const createJWT = useCallback((bucketId: string, nonceId: string, permission: NonceResponsePermission) => {

if(!privateKey) {
if (!privateKey) {
console.error("no private key found")
return
}
Expand All @@ -415,7 +415,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
const payload = {
type: "link_sharing",
permission,
iat: KJUR.jws.IntDate.get("now"),
iat: KJUR.jws.IntDate.get("now"),
bucket_id: bucketId,
nonce_id: nonceId
}
Expand All @@ -427,7 +427,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
return sJWT
}, [privateKey])

const login = async (loginType: IdentityProvider, tokenInfo?: {token: string; email: string}) => {
const login = async (loginType: IdentityProvider, tokenInfo?: { token: string; email: string }) => {
if (!TKeySdk || maintenanceMode) return
try {
setStatus("awaiting confirmation")
Expand Down Expand Up @@ -456,7 +456,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
verifierId: (loginType === "web3") ? address || "" : decodedToken.uuid,
typeOfLogin: loginType !== "web3" && loginType !== "email" ? loginType : "jwt",
accessToken: userInfo?.accessToken,
state: { }
state: {}
}
}
setUserInfo(loginResponse)
Expand All @@ -468,11 +468,11 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
sessionStorage.setItem(TORUS_POSTBOX_KEY, TKeySdk.serviceProvider.postboxKey.toString("hex"))
setStatus("logging in")
try {
const metadata = await TKeySdk.storageLayer.getMetadata<ShareStore | {message: string}>({
const metadata = await TKeySdk.storageLayer.getMetadata<ShareStore | { message: string }>({
privKey: TKeySdk.serviceProvider.postboxKey
})
console.log("metadata", metadata)
const keyNotFound = (metadata as {message: string}).message === "KEY_NOT_FOUND"
const keyNotFound = (metadata as { message: string }).message === "KEY_NOT_FOUND"
if (keyNotFound) {
console.log("New key")
setIsNewKey(true)
Expand Down Expand Up @@ -509,8 +509,8 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f

const getIdentityToken = async (
loginType: IdentityProvider,
tokenInfo?: {token: string; email: string}
): Promise<{identityToken: IdentityToken; userInfo: any}> => {
tokenInfo?: { token: string; email: string }
): Promise<{ identityToken: IdentityToken; userInfo: any }> => {
if (loginType === "email") {
const uuidToken = await filesApiClient.generateServiceIdentityToken({
identity_provider: loginType,
Expand All @@ -525,7 +525,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f

let addressToUse = address

if (!isReady || !provider) {
if (!isReady || !provider) {
const connected = await checkIsReady()

if (!connected || !provider) throw new Error("Unable to connect to wallet.")
Expand All @@ -534,7 +534,7 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
const signer = provider.getSigner()
if (!signer) throw new Error("Signer undefined")

if(!addressToUse){
if (!addressToUse) {
// checkIsReady above doesn't make sure that the address is defined
// we pull the address here to have it defined for sure
addressToUse = await signer.getAddress()
Expand Down Expand Up @@ -791,9 +791,10 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
[WEB_STORAGE_MODULE_NAME]: new WebStorageModule(true),
[SHARE_TRANSFER_MODULE_NAME]: new ShareTransferModule()
},
directParams: {
customAuthArgs: {
baseUrl: `${window.location.origin}/serviceworker`,
network: network,
networkUrl: network === "testnet" ? "https://nd-598-268-537.p2pify.com/9a34d9de132b22e6b71b52d3fde80ff1" : undefined,
enableLogging: enableLogging,
apiKey: apiKey
},
Expand Down
Loading