@tomo-inc/social-account-sdk 0.0.6 → 0.0.8

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 ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var chainsService=require('@tomo-inc/chains-service'),cubistWalletSdk=require('@tomo-inc/cubist-wallet-sdk'),walletUtils=require('@tomo-inc/wallet-utils'),cubesignerSdk=require('@cubist-labs/cubesigner-sdk'),cubistSigSdk=require('@tomo-inc/cubist-sig-sdk');var k=Object.defineProperty;var o=(a,e)=>k(a,"name",{value:e,configurable:true});var b=class{static{o(this,"CubeSocialAccount");}chainType;chainId;cubeSignService;accountData;userAPIs;constructor({chainType:e,chainId:r},t){if(!e||!walletUtils.SupportedChainTypes[e])throw new Error("chainType is wrong or not supported");this.chainType=e,this.chainId=r||walletUtils.SupportedChainTypes[e]?.chainId||"",this.accountData=t,this.cubeSignService=cubistWalletSdk.CubeSignService.getInstance();}async getAllAccounts(){let{accountWallet:e,user:r}=this.accountData||{},t={[walletUtils.ChainTypes.EVM]:[{address:e?.ethereumAddress,publicKey:"",subType:walletUtils.ChainTypes.EVM,path:""}],[walletUtils.ChainTypes.DOGE]:[{address:e?.dogeAddress,publicKey:"",subType:walletUtils.ChainTypes.DOGE,path:""}],[walletUtils.ChainTypes.SOL]:[{address:e?.solanaAddress,publicKey:"",subType:walletUtils.ChainTypes.SOL,path:""}],[walletUtils.ChainTypes.TRON]:[{address:e?.tronAddress,publicKey:"",subType:walletUtils.ChainTypes.TRON,path:""}],[walletUtils.ChainTypes.BTC]:[{address:e?.bitcoinP2trAddressMain,publicKey:e?.bitcoinP2trPubKeyMain,subType:"TAPROOT",stage:"MAIN",path:"m/86'/0'/0'/0/0"},{address:e?.bitcoinP2trAddressTest,publicKey:e?.bitcoinP2trPubKeyTest,subType:"TAPROOT",stage:"TEST",path:"m/86'/1'/0'/0/0"},{address:e?.bitcoinP2shAddressMain,publicKey:e?.bitcoinP2shPubKeyMain,subType:"NESTED_SEGWIT",stage:"MAIN",path:"m/49'/0'/0'/0/0"},{address:e?.bitcoinP2shAddressTest,publicKey:e?.bitcoinP2shPubKeyTest,subType:"NESTED_SEGWIT",stage:"TEST",path:"m/49'/1'/0'/0/0"},{address:e?.bitcoinP2wpkhAddressMain,publicKey:e?.bitcoinP2wpkhPubKeyMain,subType:"NATIVE_SEGWIT",stage:"MAIN",path:"m/84'/0'/0'/0/0"},{address:e?.bitcoinP2wpkhAddressTest,publicKey:e?.bitcoinP2wpkhPubKeyTest,subType:"NATIVE_SEGWIT",stage:"TEST",path:"m/84'/0'/0'/0/0"},{address:e?.bitcoinP2pkhAddressMain,publicKey:e?.bitcoinP2pkhPubKeyMain,subType:"LEGACY",stage:"MAIN",path:"m/44'/0'/0'/0/0"},{address:e?.bitcoinP2pkhAddressTest,publicKey:e?.bitcoinP2pkhPubKeyTest,subType:"LEGACY",stage:"TEST",path:"m/44'/1'/0'/0/0"}],[walletUtils.ChainTypes.SUI]:[{address:e?.suiAddress,publicKey:"",subType:walletUtils.ChainTypes.SUI,path:""}],[walletUtils.ChainTypes.TON]:[{address:e?.tonAddress,publicKey:"",subType:walletUtils.ChainTypes.TON,path:""}],[walletUtils.ChainTypes.COSMOS]:[{address:e?.cosmosAddress,publicKey:"",subType:walletUtils.ChainTypes.COSMOS,path:""}],[walletUtils.ChainTypes.APTOS]:[{address:e?.aptosAddress,publicKey:"",subType:walletUtils.ChainTypes.APTOS,path:""}]};return {id:r.accountID,name:r.nickname,type:chainsService.AccountType.SOCIAL,lastUsedTime:r.lastUsedTime,addresses:t,mnemonic:null,addressIndex:0,isImported:false,isBackedUp:false,isLocked:false,isFrozen:false}}async getCurrent(){let e=this.chainType,r=await this.getAllAccounts(),{address:t,publicKey:i,path:c,subType:d}=r?.addresses?.[e]?.[0]||{};return [{subType:d,address:t,path:c,publicKey:i,type:r.type,id:r.id}]}async signMessage(e){let r=await this.getCurrent(),t=this.chainType;try{let i=r[0].address;return await this.cubeSignService.signMessage(t,i,e)}catch(i){throw console.error("Error signing message with CubeSignService:",i),i}}async signTypedData(e){let r=await this.getCurrent(),t=this.chainType;try{let i=r[0].address;return await this.cubeSignService.signTypedData(t,i,e)}catch(i){throw console.error("Error signing typed data with CubeSignService:",i),i}}async signTransaction(e){let r=await this.getCurrent(),t=this.chainType,i=r[0].address;try{return await this.cubeSignService.signTransaction(t,i,e)}catch(c){throw console.error("Error signing transaction with CubeSignService:",c),c}}};var f={googleAuth:"tomo-google-authorized",xAuth:"tomo-twitter-authorized",kakaoAuth:"tomo-kakao-authorized",telegramAuth:"tomo-telegram-authorized"},G=60,P=o(({url:a,name:e,width:r,height:t})=>{let i=(window.innerHeight-(t||400))/2+window.screenY,c=(window.innerWidth-(r||400))/2+window.screenX;try{return window.open(a,e,`dialog=yes,top=${i}px,left=${c},width=${r!==void 0?r:400}px,height=${t!==void 0?t:600}px`)||null}catch(d){return console.error("Failed to open window:",d),null}},"y"),R=o(({tomoStage:a,xClientId:e,googleClientId:r})=>{let t=walletUtils.RelayOrigins[a];if(!t)throw new Error("Invalid tomo stage");let i=`${t}/x/loader`,c=`${t}/google`,d=walletUtils.CubeStages[a],h=walletUtils.CubeOrgIds[a];if(!h)throw new Error("Invalid cube stage");let y=cubesignerSdk.envs[d]||cubesignerSdk.envs.gamma,C="https://accounts.google.com/o/oauth2/v2/auth",A=o((n,g=12e4)=>new Promise((u,p)=>{if(!n){p(new Error("Popup window is null"));return}let l=setTimeout(()=>{n.close(),p(new Error("Login timeout"));},g),T=o(async w=>{if(w.origin!==t||w.data.action!=="login")return;let{data:S,type:E}=w.data,m="";try{E===f.googleAuth?m=S.code:E===f.xAuth&&(m=S?.oidcToken||""),m&&(clearTimeout(l),window.removeEventListener("message",T),n.close(),u(m));}catch(K){clearTimeout(l),window.removeEventListener("message",T),n.close(),p(K);}},"c");window.addEventListener("message",T);let O=setInterval(()=>{n.closed&&(clearTimeout(l),clearInterval(O),window.removeEventListener("message",T),p(new Error("Login cancelled by user")));},400);}),"E");return {loginByGoogle:o(async()=>{let n=window.location.origin,g=JSON.stringify({origin:n,action:"login",loadImg:""}),u={client_id:r,state:encodeURIComponent(g),redirect_uri:c,response_type:"id_token",scope:"openid",access_type:"offline",nonce:Date.now().toString(),prompt:"select_account"},p=`${C}?${new URLSearchParams(u).toString()}`,l=P({url:p,name:"Google login"});if(!l)throw new Error("Failed to open popup");return await A(l)},"loginByGoogle"),loginByX:o(async()=>{let n={target:window.location.origin,tomoStage:a,eventId:Date.now().toString(),action:"login",clientId:e},g=`${i}?${new URLSearchParams(n).toString()}`,u=P({url:g,name:"X login"});if(!u)throw new Error("Failed to open popup");return await A(u)},"loginByX"),loginByEmail:o(async n=>{if(!walletUtils.isEmail(n))throw new Error("Invalid email");return {partialOidcToken:await cubistSigSdk.emailLogin(n,y,h),lifeTime:G}},"loginByEmail")}},"N");var oe=o((a,e,r)=>{let{chainType:t,chainId:i}=e;cubistWalletSdk.CubeAccountService.getInstance().initCubeSignService();let d=new b(e,a),h=chainsService.ChainTypeServices[t];if(!h)throw new Error(`ChainTypeServices not found for chainType: ${t}`);let y=h.getInstance(t,d,r);return t===walletUtils.ChainTypes.EVM&&y.wallet_switchEthereumChain([{chainId:i}]),y},"SocialAccount");
2
+ Object.defineProperty(exports,"TomoWallet",{enumerable:true,get:function(){return chainsService.TomoWallet}});Object.defineProperty(exports,"TxTypes",{enumerable:true,get:function(){return chainsService.TxTypes}});Object.defineProperty(exports,"CubeConnect",{enumerable:true,get:function(){return cubistWalletSdk.CubeConnect}});Object.defineProperty(exports,"ChainTypes",{enumerable:true,get:function(){return walletUtils.ChainTypes}});exports.OidcAuth=R;exports.SocialAccount=oe;
@@ -0,0 +1,14 @@
1
+ import { TomoAppInfo } from '@tomo-inc/chains-service';
2
+ export { TomoAppInfo as TomoAppConfig, TomoWallet, TransactionItem, TransactionsParams, TransactionsResponse, TxTypes } from '@tomo-inc/chains-service';
3
+ import { CubeConnectResult } from '@tomo-inc/cubist-wallet-sdk';
4
+ export { CubeConfig, CubeConnect, CubeConnectResult, MfaConfig, TotpInfo } from '@tomo-inc/cubist-wallet-sdk';
5
+ import { ChainTypes } from '@tomo-inc/wallet-utils';
6
+ export { ChainTypes } from '@tomo-inc/wallet-utils';
7
+ export { EmailLoginResult, LoginType, OidcAuth } from '@tomo-inc/oidc-auth';
8
+
9
+ declare const SocialAccount: (accountData: CubeConnectResult, chainConfig: {
10
+ chainType: ChainTypes;
11
+ chainId?: string;
12
+ }, tomoAppConfig: TomoAppInfo) => any;
13
+
14
+ export { SocialAccount };
@@ -0,0 +1,14 @@
1
+ import { TomoAppInfo } from '@tomo-inc/chains-service';
2
+ export { TomoAppInfo as TomoAppConfig, TomoWallet, TransactionItem, TransactionsParams, TransactionsResponse, TxTypes } from '@tomo-inc/chains-service';
3
+ import { CubeConnectResult } from '@tomo-inc/cubist-wallet-sdk';
4
+ export { CubeConfig, CubeConnect, CubeConnectResult, MfaConfig, TotpInfo } from '@tomo-inc/cubist-wallet-sdk';
5
+ import { ChainTypes } from '@tomo-inc/wallet-utils';
6
+ export { ChainTypes } from '@tomo-inc/wallet-utils';
7
+ export { EmailLoginResult, LoginType, OidcAuth } from '@tomo-inc/oidc-auth';
8
+
9
+ declare const SocialAccount: (accountData: CubeConnectResult, chainConfig: {
10
+ chainType: ChainTypes;
11
+ chainId?: string;
12
+ }, tomoAppConfig: TomoAppInfo) => any;
13
+
14
+ export { SocialAccount };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {AccountType,ChainTypeServices}from'@tomo-inc/chains-service';export{TomoWallet,TxTypes}from'@tomo-inc/chains-service';import {CubeSignService,CubeAccountService}from'@tomo-inc/cubist-wallet-sdk';export{CubeConnect}from'@tomo-inc/cubist-wallet-sdk';import {SupportedChainTypes,ChainTypes,RelayOrigins,CubeStages,CubeOrgIds,isEmail}from'@tomo-inc/wallet-utils';export{ChainTypes}from'@tomo-inc/wallet-utils';import {envs}from'@cubist-labs/cubesigner-sdk';import {emailLogin}from'@tomo-inc/cubist-sig-sdk';var k=Object.defineProperty;var o=(a,e)=>k(a,"name",{value:e,configurable:true});var b=class{static{o(this,"CubeSocialAccount");}chainType;chainId;cubeSignService;accountData;userAPIs;constructor({chainType:e,chainId:r},t){if(!e||!SupportedChainTypes[e])throw new Error("chainType is wrong or not supported");this.chainType=e,this.chainId=r||SupportedChainTypes[e]?.chainId||"",this.accountData=t,this.cubeSignService=CubeSignService.getInstance();}async getAllAccounts(){let{accountWallet:e,user:r}=this.accountData||{},t={[ChainTypes.EVM]:[{address:e?.ethereumAddress,publicKey:"",subType:ChainTypes.EVM,path:""}],[ChainTypes.DOGE]:[{address:e?.dogeAddress,publicKey:"",subType:ChainTypes.DOGE,path:""}],[ChainTypes.SOL]:[{address:e?.solanaAddress,publicKey:"",subType:ChainTypes.SOL,path:""}],[ChainTypes.TRON]:[{address:e?.tronAddress,publicKey:"",subType:ChainTypes.TRON,path:""}],[ChainTypes.BTC]:[{address:e?.bitcoinP2trAddressMain,publicKey:e?.bitcoinP2trPubKeyMain,subType:"TAPROOT",stage:"MAIN",path:"m/86'/0'/0'/0/0"},{address:e?.bitcoinP2trAddressTest,publicKey:e?.bitcoinP2trPubKeyTest,subType:"TAPROOT",stage:"TEST",path:"m/86'/1'/0'/0/0"},{address:e?.bitcoinP2shAddressMain,publicKey:e?.bitcoinP2shPubKeyMain,subType:"NESTED_SEGWIT",stage:"MAIN",path:"m/49'/0'/0'/0/0"},{address:e?.bitcoinP2shAddressTest,publicKey:e?.bitcoinP2shPubKeyTest,subType:"NESTED_SEGWIT",stage:"TEST",path:"m/49'/1'/0'/0/0"},{address:e?.bitcoinP2wpkhAddressMain,publicKey:e?.bitcoinP2wpkhPubKeyMain,subType:"NATIVE_SEGWIT",stage:"MAIN",path:"m/84'/0'/0'/0/0"},{address:e?.bitcoinP2wpkhAddressTest,publicKey:e?.bitcoinP2wpkhPubKeyTest,subType:"NATIVE_SEGWIT",stage:"TEST",path:"m/84'/0'/0'/0/0"},{address:e?.bitcoinP2pkhAddressMain,publicKey:e?.bitcoinP2pkhPubKeyMain,subType:"LEGACY",stage:"MAIN",path:"m/44'/0'/0'/0/0"},{address:e?.bitcoinP2pkhAddressTest,publicKey:e?.bitcoinP2pkhPubKeyTest,subType:"LEGACY",stage:"TEST",path:"m/44'/1'/0'/0/0"}],[ChainTypes.SUI]:[{address:e?.suiAddress,publicKey:"",subType:ChainTypes.SUI,path:""}],[ChainTypes.TON]:[{address:e?.tonAddress,publicKey:"",subType:ChainTypes.TON,path:""}],[ChainTypes.COSMOS]:[{address:e?.cosmosAddress,publicKey:"",subType:ChainTypes.COSMOS,path:""}],[ChainTypes.APTOS]:[{address:e?.aptosAddress,publicKey:"",subType:ChainTypes.APTOS,path:""}]};return {id:r.accountID,name:r.nickname,type:AccountType.SOCIAL,lastUsedTime:r.lastUsedTime,addresses:t,mnemonic:null,addressIndex:0,isImported:false,isBackedUp:false,isLocked:false,isFrozen:false}}async getCurrent(){let e=this.chainType,r=await this.getAllAccounts(),{address:t,publicKey:i,path:c,subType:d}=r?.addresses?.[e]?.[0]||{};return [{subType:d,address:t,path:c,publicKey:i,type:r.type,id:r.id}]}async signMessage(e){let r=await this.getCurrent(),t=this.chainType;try{let i=r[0].address;return await this.cubeSignService.signMessage(t,i,e)}catch(i){throw console.error("Error signing message with CubeSignService:",i),i}}async signTypedData(e){let r=await this.getCurrent(),t=this.chainType;try{let i=r[0].address;return await this.cubeSignService.signTypedData(t,i,e)}catch(i){throw console.error("Error signing typed data with CubeSignService:",i),i}}async signTransaction(e){let r=await this.getCurrent(),t=this.chainType,i=r[0].address;try{return await this.cubeSignService.signTransaction(t,i,e)}catch(c){throw console.error("Error signing transaction with CubeSignService:",c),c}}};var f={googleAuth:"tomo-google-authorized",xAuth:"tomo-twitter-authorized",kakaoAuth:"tomo-kakao-authorized",telegramAuth:"tomo-telegram-authorized"},G=60,P=o(({url:a,name:e,width:r,height:t})=>{let i=(window.innerHeight-(t||400))/2+window.screenY,c=(window.innerWidth-(r||400))/2+window.screenX;try{return window.open(a,e,`dialog=yes,top=${i}px,left=${c},width=${r!==void 0?r:400}px,height=${t!==void 0?t:600}px`)||null}catch(d){return console.error("Failed to open window:",d),null}},"y"),R=o(({tomoStage:a,xClientId:e,googleClientId:r})=>{let t=RelayOrigins[a];if(!t)throw new Error("Invalid tomo stage");let i=`${t}/x/loader`,c=`${t}/google`,d=CubeStages[a],h=CubeOrgIds[a];if(!h)throw new Error("Invalid cube stage");let y=envs[d]||envs.gamma,C="https://accounts.google.com/o/oauth2/v2/auth",A=o((n,g=12e4)=>new Promise((u,p)=>{if(!n){p(new Error("Popup window is null"));return}let l=setTimeout(()=>{n.close(),p(new Error("Login timeout"));},g),T=o(async w=>{if(w.origin!==t||w.data.action!=="login")return;let{data:S,type:E}=w.data,m="";try{E===f.googleAuth?m=S.code:E===f.xAuth&&(m=S?.oidcToken||""),m&&(clearTimeout(l),window.removeEventListener("message",T),n.close(),u(m));}catch(K){clearTimeout(l),window.removeEventListener("message",T),n.close(),p(K);}},"c");window.addEventListener("message",T);let O=setInterval(()=>{n.closed&&(clearTimeout(l),clearInterval(O),window.removeEventListener("message",T),p(new Error("Login cancelled by user")));},400);}),"E");return {loginByGoogle:o(async()=>{let n=window.location.origin,g=JSON.stringify({origin:n,action:"login",loadImg:""}),u={client_id:r,state:encodeURIComponent(g),redirect_uri:c,response_type:"id_token",scope:"openid",access_type:"offline",nonce:Date.now().toString(),prompt:"select_account"},p=`${C}?${new URLSearchParams(u).toString()}`,l=P({url:p,name:"Google login"});if(!l)throw new Error("Failed to open popup");return await A(l)},"loginByGoogle"),loginByX:o(async()=>{let n={target:window.location.origin,tomoStage:a,eventId:Date.now().toString(),action:"login",clientId:e},g=`${i}?${new URLSearchParams(n).toString()}`,u=P({url:g,name:"X login"});if(!u)throw new Error("Failed to open popup");return await A(u)},"loginByX"),loginByEmail:o(async n=>{if(!isEmail(n))throw new Error("Invalid email");return {partialOidcToken:await emailLogin(n,y,h),lifeTime:G}},"loginByEmail")}},"N");var oe=o((a,e,r)=>{let{chainType:t,chainId:i}=e;CubeAccountService.getInstance().initCubeSignService();let d=new b(e,a),h=ChainTypeServices[t];if(!h)throw new Error(`ChainTypeServices not found for chainType: ${t}`);let y=h.getInstance(t,d,r);return t===ChainTypes.EVM&&y.wallet_switchEthereumChain([{chainId:i}]),y},"SocialAccount");
2
+ export{R as OidcAuth,oe as SocialAccount};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/social-account-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -25,10 +25,10 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@tomo-inc/cubist-sig-sdk": "^1.1.0",
29
- "@tomo-inc/chains-service": "0.0.4",
30
- "@tomo-inc/wallet-utils": "0.0.3",
31
- "@tomo-inc/cubist-wallet-sdk": "0.0.5"
28
+ "@tomo-inc/chains-service": "0.0.6",
29
+ "@tomo-inc/cubist-sig-sdk": "1.1.0",
30
+ "@tomo-inc/cubist-wallet-sdk": "0.0.7",
31
+ "@tomo-inc/wallet-utils": "0.0.5"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.11.19",