@tomo-inc/social-account-sdk 0.0.2-alpha.0 → 0.0.2-alpha.2

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.
@@ -1,221 +0,0 @@
1
- import { ChainTypes } from "@tomo-inc/wallet-utils";
2
-
3
- import { AccountType, ChainAddress, IAccount } from "@tomo-inc/chains-service";
4
- import { CubeSignService, CubeConnectResult } from "@tomo-inc/cubist-wallet-sdk";
5
-
6
- export class CubeSocialAccount {
7
- private chainType: ChainTypes;
8
- private chainId: string;
9
- public cubeSignService: CubeSignService;
10
- public accountData: CubeConnectResult;
11
- public userAPIs: any;
12
-
13
- public constructor(
14
- { chainType, chainId }: { chainType: ChainTypes; chainId: string },
15
- accountData: CubeConnectResult,
16
- ) {
17
- this.chainType = chainType;
18
- this.chainId = chainId;
19
- this.accountData = accountData;
20
-
21
- this.cubeSignService = CubeSignService.getInstance();
22
- }
23
-
24
- public async getAllAccounts(): Promise<IAccount> {
25
- const { accountWallet, user }: CubeConnectResult = this.accountData || {};
26
- const addresses: Record<ChainTypes, ChainAddress[]> = {
27
- [ChainTypes.EVM]: [
28
- {
29
- address: accountWallet?.ethereumAddress,
30
- publicKey: "",
31
- subType: ChainTypes.EVM,
32
- path: "",
33
- },
34
- ],
35
- [ChainTypes.DOGE]: [
36
- {
37
- address: accountWallet?.dogeAddress,
38
- publicKey: "",
39
- subType: ChainTypes.DOGE,
40
- path: "",
41
- },
42
- ],
43
- [ChainTypes.SOL]: [
44
- {
45
- address: accountWallet?.solanaAddress,
46
- publicKey: "",
47
- subType: ChainTypes.SOL,
48
- path: "",
49
- },
50
- ],
51
- [ChainTypes.TRON]: [
52
- {
53
- address: accountWallet?.tronAddress,
54
- publicKey: "",
55
- subType: ChainTypes.TRON,
56
- path: "",
57
- },
58
- ],
59
- [ChainTypes.BTC]: [
60
- {
61
- address: accountWallet?.bitcoinP2trAddressMain,
62
- publicKey: accountWallet?.bitcoinP2trPubKeyMain,
63
- subType: "TAPROOT",
64
- stage: "MAIN",
65
- path: "m/86'/0'/0'/0/0",
66
- },
67
- {
68
- address: accountWallet?.bitcoinP2trAddressTest,
69
- publicKey: accountWallet?.bitcoinP2trPubKeyTest,
70
- subType: "TAPROOT",
71
- stage: "TEST",
72
- path: "m/86'/1'/0'/0/0",
73
- },
74
- {
75
- address: accountWallet?.bitcoinP2shAddressMain,
76
- publicKey: accountWallet?.bitcoinP2shPubKeyMain,
77
- subType: "NESTED_SEGWIT",
78
- stage: "MAIN",
79
- path: "m/49'/0'/0'/0/0",
80
- },
81
- {
82
- address: accountWallet?.bitcoinP2shAddressTest,
83
- publicKey: accountWallet?.bitcoinP2shPubKeyTest,
84
- subType: "NESTED_SEGWIT",
85
- stage: "TEST",
86
- path: "m/49'/1'/0'/0/0",
87
- },
88
- {
89
- address: accountWallet?.bitcoinP2wpkhAddressMain,
90
- publicKey: accountWallet?.bitcoinP2wpkhPubKeyMain,
91
- subType: "NATIVE_SEGWIT",
92
- stage: "MAIN",
93
- path: "m/84'/0'/0'/0/0",
94
- },
95
- {
96
- address: accountWallet?.bitcoinP2wpkhAddressTest,
97
- publicKey: accountWallet?.bitcoinP2wpkhPubKeyTest,
98
- subType: "NATIVE_SEGWIT",
99
- stage: "TEST",
100
- path: "m/84'/0'/0'/0/0",
101
- },
102
- {
103
- address: accountWallet?.bitcoinP2pkhAddressMain,
104
- publicKey: accountWallet?.bitcoinP2pkhPubKeyMain,
105
- subType: "LEGACY",
106
- stage: "MAIN",
107
- path: "m/44'/0'/0'/0/0",
108
- },
109
- {
110
- address: accountWallet?.bitcoinP2pkhAddressTest,
111
- publicKey: accountWallet?.bitcoinP2pkhPubKeyTest,
112
- subType: "LEGACY",
113
- stage: "TEST",
114
- path: "m/44'/1'/0'/0/0",
115
- },
116
- ],
117
- [ChainTypes.SUI]: [
118
- {
119
- address: accountWallet?.suiAddress,
120
- publicKey: "",
121
- subType: ChainTypes.SUI,
122
- path: "",
123
- },
124
- ],
125
- [ChainTypes.TON]: [
126
- {
127
- address: accountWallet?.tonAddress,
128
- publicKey: "",
129
- subType: ChainTypes.TON,
130
- path: "",
131
- },
132
- ],
133
- [ChainTypes.COSMOS]: [
134
- {
135
- address: accountWallet?.cosmosAddress,
136
- publicKey: "",
137
- subType: ChainTypes.COSMOS,
138
- path: "",
139
- },
140
- ],
141
- [ChainTypes.APTOS]: [
142
- {
143
- address: accountWallet?.aptosAddress,
144
- publicKey: "",
145
- subType: ChainTypes.APTOS,
146
- path: "",
147
- },
148
- ],
149
- };
150
-
151
- return {
152
- id: user.accountID,
153
- name: user.nickname,
154
- type: AccountType.SOCIAL,
155
- lastUsedTime: user.lastUsedTime,
156
- addresses,
157
- mnemonic: null,
158
- addressIndex: 0,
159
- isImported: false,
160
- isBackedUp: false,
161
- isLocked: false,
162
- isFrozen: false,
163
- };
164
- }
165
-
166
- public async getCurrent(): Promise<any[]> {
167
- const chainType = this.chainType;
168
- const account = await this.getAllAccounts();
169
- const { address, publicKey, path, subType } = account?.addresses?.[chainType]?.[0] || {};
170
-
171
- return [
172
- {
173
- subType,
174
- address,
175
- path,
176
- publicKey,
177
- type: account.type,
178
- id: account.id,
179
- },
180
- ];
181
- }
182
-
183
- public async signMessage(message: string): Promise<any> {
184
- const currentAccounts = await this.getCurrent();
185
- const chainType = this.chainType;
186
-
187
- try {
188
- const address = currentAccounts[0].address;
189
- return await this.cubeSignService.signMessage(chainType, address, message);
190
- } catch (error) {
191
- console.error("Error signing message with CubeSignService:", error);
192
- throw error;
193
- }
194
- }
195
-
196
- public async signTypedData(typedData: any): Promise<any> {
197
- const currentAccounts = await this.getCurrent();
198
- const chainType = this.chainType;
199
-
200
- try {
201
- const address = currentAccounts[0].address;
202
- return await this.cubeSignService.signTypedData(chainType, address, typedData);
203
- } catch (error) {
204
- console.error("Error signing typed data with CubeSignService:", error);
205
- throw error;
206
- }
207
- }
208
-
209
- //VersionedTransaction cannot through entirely to background by sendMessage
210
- public async signTransaction(unsignedTx: any): Promise<any> {
211
- const currentAccounts = await this.getCurrent();
212
- const chainType = this.chainType;
213
- const address = currentAccounts[0].address;
214
- try {
215
- return await this.cubeSignService.signTransaction(chainType, address, unsignedTx);
216
- } catch (error) {
217
- console.error("Error signing transaction with CubeSignService:", error);
218
- throw error;
219
- }
220
- }
221
- }
package/src/index.ts DELETED
@@ -1,46 +0,0 @@
1
- import { ChainTypes } from "@tomo-inc/wallet-utils";
2
- import {
3
- ChainTypeServices,
4
- TomoWallet,
5
- TxTypes,
6
- TransactionsParams,
7
- TransactionsResponse,
8
- TransactionItem,
9
- TomoAppInfo as TomoAppConfig,
10
- } from "@tomo-inc/chains-service";
11
- import { CubeSocialAccount } from "./cube-account";
12
- import { CubeAccountService, CubeConnectResult } from "@tomo-inc/cubist-wallet-sdk";
13
-
14
- export const SocialAccount = (
15
- accountData: CubeConnectResult,
16
- chainConfig: { chainType: ChainTypes; chainId: string },
17
- tomoAppConfig: TomoAppConfig,
18
- ): any => {
19
- const { chainType, chainId } = chainConfig;
20
-
21
- const cubeAccountService = CubeAccountService.getInstance();
22
- cubeAccountService.initCubeSignService();
23
-
24
- //generate address, signMessage, signTransaction, signTypedData
25
- const socialAccount = new CubeSocialAccount(chainConfig, accountData);
26
-
27
- const CurrentService = ChainTypeServices[chainType as keyof typeof ChainTypeServices];
28
-
29
- if (!CurrentService) {
30
- throw new Error(`ChainTypeServices not found for chainType: ${chainType}`);
31
- }
32
-
33
- const currentService = CurrentService.getInstance(chainType, socialAccount, tomoAppConfig);
34
- currentService.wallet_switchEthereumChain([{ chainId }]);
35
-
36
- return currentService;
37
- };
38
-
39
- export { OidcAuth } from "@tomo-inc/oidc-auth";
40
- export type { LoginType, EmailLoginResult } from "@tomo-inc/oidc-auth";
41
-
42
- export { CubeConnect } from "@tomo-inc/cubist-wallet-sdk";
43
- export type { CubeConnectResult, CubeConfig, MfaConfig, TotpInfo } from "@tomo-inc/cubist-wallet-sdk";
44
-
45
- export { TomoWallet, TxTypes, ChainTypes };
46
- export type { TransactionsParams, TransactionsResponse, TransactionItem, TomoAppConfig };
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": "./src"
5
- },
6
- "include": ["src"]
7
- }