@tomo-inc/oidc-auth 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +2 -0
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var cubesignerSdk=require('@cubist-labs/cubesigner-sdk'),cubistSigSdk=require('@tomo-inc/cubist-sig-sdk'),walletUtils=require('@tomo-inc/wallet-utils');var f={googleAuth:"tomo-google-authorized",xAuth:"tomo-twitter-authorized",kakaoAuth:"tomo-kakao-authorized",telegramAuth:"tomo-telegram-authorized"},L=60;var y=({url:i,name:m,width:s,height:n})=>{let u=(window.innerHeight-(n||400))/2+window.screenY,w=(window.innerWidth-(s||400))/2+window.screenX;try{let t=window.open(i,m,`dialog=yes,top=${u}px,left=${w},width=${s!==void 0?s:400}px,height=${n!==void 0?n:600}px`);return t||null}catch(t){return console.error("Failed to open window:",t),null}};var N=({tomoStage:i,xClientId:m,googleClientId:s})=>{let n=walletUtils.RelayOrigins[i];if(!n)throw new Error("Invalid tomo stage");let u=`${n}/x/loader`,w=`${n}/google`,t=walletUtils.CubeStages[i],h=walletUtils.CubeOrgIds[i];if(!h)throw new Error("Invalid cube stage");let b=cubesignerSdk.envs[t]||cubesignerSdk.envs.gamma,v="https://accounts.google.com/o/oauth2/v2/auth",E=(e,r=12e4)=>new Promise((l,o)=>{if(!e){o(new Error("Popup window is null"));return}let a=setTimeout(()=>{e.close(),o(new Error("Login timeout"));},r),c=async p=>{if(p.origin!==n||p.data.action!=="login")return;let{data:g,type:T}=p.data,d="";try{T===f.googleAuth?d=g.code:T===f.xAuth&&(d=(g==null?void 0:g.oidcToken)||""),d&&(clearTimeout(a),window.removeEventListener("message",c),e.close(),l(d));}catch(k){clearTimeout(a),window.removeEventListener("message",c),e.close(),o(k);}};window.addEventListener("message",c);let O=setInterval(()=>{e.closed&&(clearTimeout(a),clearInterval(O),window.removeEventListener("message",c),o(new Error("Login cancelled by user")));},400);});return {loginByGoogle:async()=>{let e=window.location.origin,r=JSON.stringify({origin:e,action:"login",loadImg:""}),l={client_id:s,state:encodeURIComponent(r),redirect_uri:w,response_type:"id_token",scope:"openid",access_type:"offline",nonce:Date.now().toString(),prompt:"select_account"},o=`${v}?${new URLSearchParams(l).toString()}`,a=y({url:o,name:"Google login"});if(!a)throw new Error("Failed to open popup");return await E(a)},loginByX:async()=>{let r={target:window.location.origin,tomoStage:i,eventId:Date.now().toString(),action:"login",clientId:m},l=`${u}?${new URLSearchParams(r).toString()}`,o=y({url:l,name:"X login"});if(!o)throw new Error("Failed to open popup");return await E(o)},loginByEmail:async e=>{if(!walletUtils.isEmail(e))throw new Error("Invalid email");return {partialOidcToken:await cubistSigSdk.emailLogin(e,b,h),lifeTime:L}}}};
|
|
2
|
+
exports.OidcAuth=N;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TomoStage } from '@tomo-inc/wallet-utils';
|
|
2
|
+
|
|
3
|
+
type LoginType = "google" | "x" | "email";
|
|
4
|
+
type EmailLoginResult = {
|
|
5
|
+
partialOidcToken: string;
|
|
6
|
+
lifeTime: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
interface Config {
|
|
10
|
+
tomoStage: TomoStage;
|
|
11
|
+
xClientId: string;
|
|
12
|
+
googleClientId: string;
|
|
13
|
+
}
|
|
14
|
+
declare const OidcAuth: ({ tomoStage, xClientId, googleClientId }: Config) => {
|
|
15
|
+
loginByGoogle: () => Promise<string>;
|
|
16
|
+
loginByX: () => Promise<string>;
|
|
17
|
+
loginByEmail: (email: string) => Promise<EmailLoginResult>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { type EmailLoginResult, type LoginType, OidcAuth };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TomoStage } from '@tomo-inc/wallet-utils';
|
|
2
|
+
|
|
3
|
+
type LoginType = "google" | "x" | "email";
|
|
4
|
+
type EmailLoginResult = {
|
|
5
|
+
partialOidcToken: string;
|
|
6
|
+
lifeTime: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
interface Config {
|
|
10
|
+
tomoStage: TomoStage;
|
|
11
|
+
xClientId: string;
|
|
12
|
+
googleClientId: string;
|
|
13
|
+
}
|
|
14
|
+
declare const OidcAuth: ({ tomoStage, xClientId, googleClientId }: Config) => {
|
|
15
|
+
loginByGoogle: () => Promise<string>;
|
|
16
|
+
loginByX: () => Promise<string>;
|
|
17
|
+
loginByEmail: (email: string) => Promise<EmailLoginResult>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { type EmailLoginResult, type LoginType, OidcAuth };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {envs}from'@cubist-labs/cubesigner-sdk';import {emailLogin}from'@tomo-inc/cubist-sig-sdk';import {RelayOrigins,CubeStages,CubeOrgIds,isEmail}from'@tomo-inc/wallet-utils';var f={googleAuth:"tomo-google-authorized",xAuth:"tomo-twitter-authorized",kakaoAuth:"tomo-kakao-authorized",telegramAuth:"tomo-telegram-authorized"},L=60;var y=({url:i,name:m,width:s,height:n})=>{let u=(window.innerHeight-(n||400))/2+window.screenY,w=(window.innerWidth-(s||400))/2+window.screenX;try{let t=window.open(i,m,`dialog=yes,top=${u}px,left=${w},width=${s!==void 0?s:400}px,height=${n!==void 0?n:600}px`);return t||null}catch(t){return console.error("Failed to open window:",t),null}};var N=({tomoStage:i,xClientId:m,googleClientId:s})=>{let n=RelayOrigins[i];if(!n)throw new Error("Invalid tomo stage");let u=`${n}/x/loader`,w=`${n}/google`,t=CubeStages[i],h=CubeOrgIds[i];if(!h)throw new Error("Invalid cube stage");let b=envs[t]||envs.gamma,v="https://accounts.google.com/o/oauth2/v2/auth",E=(e,r=12e4)=>new Promise((l,o)=>{if(!e){o(new Error("Popup window is null"));return}let a=setTimeout(()=>{e.close(),o(new Error("Login timeout"));},r),c=async p=>{if(p.origin!==n||p.data.action!=="login")return;let{data:g,type:T}=p.data,d="";try{T===f.googleAuth?d=g.code:T===f.xAuth&&(d=(g==null?void 0:g.oidcToken)||""),d&&(clearTimeout(a),window.removeEventListener("message",c),e.close(),l(d));}catch(k){clearTimeout(a),window.removeEventListener("message",c),e.close(),o(k);}};window.addEventListener("message",c);let O=setInterval(()=>{e.closed&&(clearTimeout(a),clearInterval(O),window.removeEventListener("message",c),o(new Error("Login cancelled by user")));},400);});return {loginByGoogle:async()=>{let e=window.location.origin,r=JSON.stringify({origin:e,action:"login",loadImg:""}),l={client_id:s,state:encodeURIComponent(r),redirect_uri:w,response_type:"id_token",scope:"openid",access_type:"offline",nonce:Date.now().toString(),prompt:"select_account"},o=`${v}?${new URLSearchParams(l).toString()}`,a=y({url:o,name:"Google login"});if(!a)throw new Error("Failed to open popup");return await E(a)},loginByX:async()=>{let r={target:window.location.origin,tomoStage:i,eventId:Date.now().toString(),action:"login",clientId:m},l=`${u}?${new URLSearchParams(r).toString()}`,o=y({url:l,name:"X login"});if(!o)throw new Error("Failed to open popup");return await E(o)},loginByEmail:async e=>{if(!isEmail(e))throw new Error("Invalid email");return {partialOidcToken:await emailLogin(e,b,h),lifeTime:L}}}};
|
|
2
|
+
export{N as OidcAuth};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomo-inc/oidc-auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"author": "tomo.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@cubist-labs/cubesigner-sdk": "0.4.98-0",
|
|
20
20
|
"@tomo-inc/cubist-sig-sdk": "1.1.0",
|
|
21
|
-
"@tomo-inc/wallet-utils": "
|
|
21
|
+
"@tomo-inc/wallet-utils": "0.0.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/crypto-js": "^4.2.2",
|