@tomo-inc/social-account-sdk 0.0.2-alpha.0
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/.turbo/turbo-build.log +34 -0
- package/.turbo/turbo-lint.log +14 -0
- package/.turbo/turbo-test.log +13 -0
- package/CHANGELOG.md +3 -0
- package/README.md +1 -0
- package/dist/index.cjs +248 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +229 -0
- package/package.json +49 -0
- package/src/cube-account.ts +221 -0
- package/src/index.ts +46 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
> @tomo-inc/social-account-sdk@0.0.1 build /home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --dts --treeshake
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.0
|
|
8
|
+
[34mCLI[39m Target: es2017
|
|
9
|
+
[34mESM[39m Build start
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mCannot find base config file "../../tsconfig.json"[0m [tsconfig.json]
|
|
12
|
+
|
|
13
|
+
tsconfig.json:2:13:
|
|
14
|
+
[37m 2 │ "extends": [32m"../../tsconfig.json"[37m,
|
|
15
|
+
╵ [32m~~~~~~~~~~~~~~~~~~~~~[0m
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mCannot find base config file "../../tsconfig.json"[0m [tsconfig.json]
|
|
19
|
+
|
|
20
|
+
tsconfig.json:2:13:
|
|
21
|
+
[37m 2 │ "extends": [32m"../../tsconfig.json"[37m,
|
|
22
|
+
╵ [32m~~~~~~~~~~~~~~~~~~~~~[0m
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
[32mESM[39m [1mdist/index.js [22m[32m7.94 KB[39m
|
|
26
|
+
[32mESM[39m ⚡️ Build success in 170ms
|
|
27
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m8.62 KB[39m
|
|
28
|
+
[32mCJS[39m ⚡️ Build success in 171ms
|
|
29
|
+
[34mDTS[39m Build start
|
|
30
|
+
error TS5083: Cannot read file '/home/runner/work/tomo-wallet/tomo-wallet/out/full/tsconfig.json'.
|
|
31
|
+
|
|
32
|
+
[32mDTS[39m ⚡️ Build success in 3484ms
|
|
33
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m760.00 B[39m
|
|
34
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m760.00 B[39m
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> @tomo-inc/social-account-sdk@0.0.1 lint /home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk
|
|
3
|
+
> eslint src/**/*.ts
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk/src/cube-account.ts
|
|
7
|
+
1:1 error Parsing error: The keyword 'import' is reserved
|
|
8
|
+
|
|
9
|
+
/home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk/src/index.ts
|
|
10
|
+
1:1 error Parsing error: The keyword 'import' is reserved
|
|
11
|
+
|
|
12
|
+
✖ 2 problems (2 errors, 0 warnings)
|
|
13
|
+
|
|
14
|
+
ELIFECYCLE Command failed with exit code 1.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
> @tomo-inc/social-account-sdk@0.0.1 test /home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk
|
|
3
|
+
> vitest run
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/home/runner/work/tomo-wallet/tomo-wallet/out/full/packages/social-account-sdk[39m
|
|
7
|
+
|
|
8
|
+
[31mNo test files found, exiting with code 1
|
|
9
|
+
[39m
|
|
10
|
+
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
11
|
+
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
12
|
+
|
|
13
|
+
ELIFECYCLE Test failed. See above for more details.
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @tomo-inc/social-account-sdk
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var walletUtils = require('@tomo-inc/wallet-utils');
|
|
4
|
+
var chainsService = require('@tomo-inc/chains-service');
|
|
5
|
+
var cubistWalletSdk = require('@tomo-inc/cubist-wallet-sdk');
|
|
6
|
+
var oidcAuth = require('@tomo-inc/oidc-auth');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
var CubeSocialAccount = class {
|
|
12
|
+
constructor({ chainType, chainId }, accountData) {
|
|
13
|
+
__publicField(this, "chainType");
|
|
14
|
+
__publicField(this, "chainId");
|
|
15
|
+
__publicField(this, "cubeSignService");
|
|
16
|
+
__publicField(this, "accountData");
|
|
17
|
+
__publicField(this, "userAPIs");
|
|
18
|
+
this.chainType = chainType;
|
|
19
|
+
this.chainId = chainId;
|
|
20
|
+
this.accountData = accountData;
|
|
21
|
+
this.cubeSignService = cubistWalletSdk.CubeSignService.getInstance();
|
|
22
|
+
}
|
|
23
|
+
async getAllAccounts() {
|
|
24
|
+
const { accountWallet, user } = this.accountData || {};
|
|
25
|
+
const addresses = {
|
|
26
|
+
[walletUtils.ChainTypes.EVM]: [
|
|
27
|
+
{
|
|
28
|
+
address: accountWallet == null ? void 0 : accountWallet.ethereumAddress,
|
|
29
|
+
publicKey: "",
|
|
30
|
+
subType: walletUtils.ChainTypes.EVM,
|
|
31
|
+
path: ""
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
[walletUtils.ChainTypes.DOGE]: [
|
|
35
|
+
{
|
|
36
|
+
address: accountWallet == null ? void 0 : accountWallet.dogeAddress,
|
|
37
|
+
publicKey: "",
|
|
38
|
+
subType: walletUtils.ChainTypes.DOGE,
|
|
39
|
+
path: ""
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
[walletUtils.ChainTypes.SOL]: [
|
|
43
|
+
{
|
|
44
|
+
address: accountWallet == null ? void 0 : accountWallet.solanaAddress,
|
|
45
|
+
publicKey: "",
|
|
46
|
+
subType: walletUtils.ChainTypes.SOL,
|
|
47
|
+
path: ""
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
[walletUtils.ChainTypes.TRON]: [
|
|
51
|
+
{
|
|
52
|
+
address: accountWallet == null ? void 0 : accountWallet.tronAddress,
|
|
53
|
+
publicKey: "",
|
|
54
|
+
subType: walletUtils.ChainTypes.TRON,
|
|
55
|
+
path: ""
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
[walletUtils.ChainTypes.BTC]: [
|
|
59
|
+
{
|
|
60
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2trAddressMain,
|
|
61
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2trPubKeyMain,
|
|
62
|
+
subType: "TAPROOT",
|
|
63
|
+
stage: "MAIN",
|
|
64
|
+
path: "m/86'/0'/0'/0/0"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2trAddressTest,
|
|
68
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2trPubKeyTest,
|
|
69
|
+
subType: "TAPROOT",
|
|
70
|
+
stage: "TEST",
|
|
71
|
+
path: "m/86'/1'/0'/0/0"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2shAddressMain,
|
|
75
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2shPubKeyMain,
|
|
76
|
+
subType: "NESTED_SEGWIT",
|
|
77
|
+
stage: "MAIN",
|
|
78
|
+
path: "m/49'/0'/0'/0/0"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2shAddressTest,
|
|
82
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2shPubKeyTest,
|
|
83
|
+
subType: "NESTED_SEGWIT",
|
|
84
|
+
stage: "TEST",
|
|
85
|
+
path: "m/49'/1'/0'/0/0"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhAddressMain,
|
|
89
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhPubKeyMain,
|
|
90
|
+
subType: "NATIVE_SEGWIT",
|
|
91
|
+
stage: "MAIN",
|
|
92
|
+
path: "m/84'/0'/0'/0/0"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhAddressTest,
|
|
96
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhPubKeyTest,
|
|
97
|
+
subType: "NATIVE_SEGWIT",
|
|
98
|
+
stage: "TEST",
|
|
99
|
+
path: "m/84'/0'/0'/0/0"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhAddressMain,
|
|
103
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhPubKeyMain,
|
|
104
|
+
subType: "LEGACY",
|
|
105
|
+
stage: "MAIN",
|
|
106
|
+
path: "m/44'/0'/0'/0/0"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhAddressTest,
|
|
110
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhPubKeyTest,
|
|
111
|
+
subType: "LEGACY",
|
|
112
|
+
stage: "TEST",
|
|
113
|
+
path: "m/44'/1'/0'/0/0"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
[walletUtils.ChainTypes.SUI]: [
|
|
117
|
+
{
|
|
118
|
+
address: accountWallet == null ? void 0 : accountWallet.suiAddress,
|
|
119
|
+
publicKey: "",
|
|
120
|
+
subType: walletUtils.ChainTypes.SUI,
|
|
121
|
+
path: ""
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
[walletUtils.ChainTypes.TON]: [
|
|
125
|
+
{
|
|
126
|
+
address: accountWallet == null ? void 0 : accountWallet.tonAddress,
|
|
127
|
+
publicKey: "",
|
|
128
|
+
subType: walletUtils.ChainTypes.TON,
|
|
129
|
+
path: ""
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
[walletUtils.ChainTypes.COSMOS]: [
|
|
133
|
+
{
|
|
134
|
+
address: accountWallet == null ? void 0 : accountWallet.cosmosAddress,
|
|
135
|
+
publicKey: "",
|
|
136
|
+
subType: walletUtils.ChainTypes.COSMOS,
|
|
137
|
+
path: ""
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
[walletUtils.ChainTypes.APTOS]: [
|
|
141
|
+
{
|
|
142
|
+
address: accountWallet == null ? void 0 : accountWallet.aptosAddress,
|
|
143
|
+
publicKey: "",
|
|
144
|
+
subType: walletUtils.ChainTypes.APTOS,
|
|
145
|
+
path: ""
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
id: user.accountID,
|
|
151
|
+
name: user.nickname,
|
|
152
|
+
type: chainsService.AccountType.SOCIAL,
|
|
153
|
+
lastUsedTime: user.lastUsedTime,
|
|
154
|
+
addresses,
|
|
155
|
+
mnemonic: null,
|
|
156
|
+
addressIndex: 0,
|
|
157
|
+
isImported: false,
|
|
158
|
+
isBackedUp: false,
|
|
159
|
+
isLocked: false,
|
|
160
|
+
isFrozen: false
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async getCurrent() {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
const chainType = this.chainType;
|
|
166
|
+
const account = await this.getAllAccounts();
|
|
167
|
+
const { address, publicKey, path, subType } = ((_b = (_a = account == null ? void 0 : account.addresses) == null ? void 0 : _a[chainType]) == null ? void 0 : _b[0]) || {};
|
|
168
|
+
return [
|
|
169
|
+
{
|
|
170
|
+
subType,
|
|
171
|
+
address,
|
|
172
|
+
path,
|
|
173
|
+
publicKey,
|
|
174
|
+
type: account.type,
|
|
175
|
+
id: account.id
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
async signMessage(message) {
|
|
180
|
+
const currentAccounts = await this.getCurrent();
|
|
181
|
+
const chainType = this.chainType;
|
|
182
|
+
try {
|
|
183
|
+
const address = currentAccounts[0].address;
|
|
184
|
+
return await this.cubeSignService.signMessage(chainType, address, message);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error("Error signing message with CubeSignService:", error);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async signTypedData(typedData) {
|
|
191
|
+
const currentAccounts = await this.getCurrent();
|
|
192
|
+
const chainType = this.chainType;
|
|
193
|
+
try {
|
|
194
|
+
const address = currentAccounts[0].address;
|
|
195
|
+
return await this.cubeSignService.signTypedData(chainType, address, typedData);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("Error signing typed data with CubeSignService:", error);
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//VersionedTransaction cannot through entirely to background by sendMessage
|
|
202
|
+
async signTransaction(unsignedTx) {
|
|
203
|
+
const currentAccounts = await this.getCurrent();
|
|
204
|
+
const chainType = this.chainType;
|
|
205
|
+
const address = currentAccounts[0].address;
|
|
206
|
+
try {
|
|
207
|
+
return await this.cubeSignService.signTransaction(chainType, address, unsignedTx);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.error("Error signing transaction with CubeSignService:", error);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var SocialAccount = (accountData, chainConfig, tomoAppConfig) => {
|
|
215
|
+
const { chainType, chainId } = chainConfig;
|
|
216
|
+
const cubeAccountService = cubistWalletSdk.CubeAccountService.getInstance();
|
|
217
|
+
cubeAccountService.initCubeSignService();
|
|
218
|
+
const socialAccount = new CubeSocialAccount(chainConfig, accountData);
|
|
219
|
+
const CurrentService = chainsService.ChainTypeServices[chainType];
|
|
220
|
+
if (!CurrentService) {
|
|
221
|
+
throw new Error(`ChainTypeServices not found for chainType: ${chainType}`);
|
|
222
|
+
}
|
|
223
|
+
const currentService = CurrentService.getInstance(chainType, socialAccount, tomoAppConfig);
|
|
224
|
+
currentService.wallet_switchEthereumChain([{ chainId }]);
|
|
225
|
+
return currentService;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
Object.defineProperty(exports, "ChainTypes", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function () { return walletUtils.ChainTypes; }
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(exports, "TomoWallet", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get: function () { return chainsService.TomoWallet; }
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, "TxTypes", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () { return chainsService.TxTypes; }
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "CubeConnect", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function () { return cubistWalletSdk.CubeConnect; }
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(exports, "OidcAuth", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
get: function () { return oidcAuth.OidcAuth; }
|
|
247
|
+
});
|
|
248
|
+
exports.SocialAccount = SocialAccount;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
2
|
+
export { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
3
|
+
import { TomoAppInfo } from '@tomo-inc/chains-service';
|
|
4
|
+
export { TomoAppInfo as TomoAppConfig, TomoWallet, TransactionItem, TransactionsParams, TransactionsResponse, TxTypes } from '@tomo-inc/chains-service';
|
|
5
|
+
import { CubeConnectResult } from '@tomo-inc/cubist-wallet-sdk';
|
|
6
|
+
export { CubeConfig, CubeConnect, CubeConnectResult, MfaConfig, TotpInfo } from '@tomo-inc/cubist-wallet-sdk';
|
|
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.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
2
|
+
export { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
3
|
+
import { TomoAppInfo } from '@tomo-inc/chains-service';
|
|
4
|
+
export { TomoAppInfo as TomoAppConfig, TomoWallet, TransactionItem, TransactionsParams, TransactionsResponse, TxTypes } from '@tomo-inc/chains-service';
|
|
5
|
+
import { CubeConnectResult } from '@tomo-inc/cubist-wallet-sdk';
|
|
6
|
+
export { CubeConfig, CubeConnect, CubeConnectResult, MfaConfig, TotpInfo } from '@tomo-inc/cubist-wallet-sdk';
|
|
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,229 @@
|
|
|
1
|
+
import { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
2
|
+
export { ChainTypes } from '@tomo-inc/wallet-utils';
|
|
3
|
+
import { ChainTypeServices, AccountType } from '@tomo-inc/chains-service';
|
|
4
|
+
export { TomoWallet, TxTypes } from '@tomo-inc/chains-service';
|
|
5
|
+
import { CubeAccountService, CubeSignService } from '@tomo-inc/cubist-wallet-sdk';
|
|
6
|
+
export { CubeConnect } from '@tomo-inc/cubist-wallet-sdk';
|
|
7
|
+
export { OidcAuth } from '@tomo-inc/oidc-auth';
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
+
var CubeSocialAccount = class {
|
|
13
|
+
constructor({ chainType, chainId }, accountData) {
|
|
14
|
+
__publicField(this, "chainType");
|
|
15
|
+
__publicField(this, "chainId");
|
|
16
|
+
__publicField(this, "cubeSignService");
|
|
17
|
+
__publicField(this, "accountData");
|
|
18
|
+
__publicField(this, "userAPIs");
|
|
19
|
+
this.chainType = chainType;
|
|
20
|
+
this.chainId = chainId;
|
|
21
|
+
this.accountData = accountData;
|
|
22
|
+
this.cubeSignService = CubeSignService.getInstance();
|
|
23
|
+
}
|
|
24
|
+
async getAllAccounts() {
|
|
25
|
+
const { accountWallet, user } = this.accountData || {};
|
|
26
|
+
const addresses = {
|
|
27
|
+
[ChainTypes.EVM]: [
|
|
28
|
+
{
|
|
29
|
+
address: accountWallet == null ? void 0 : accountWallet.ethereumAddress,
|
|
30
|
+
publicKey: "",
|
|
31
|
+
subType: ChainTypes.EVM,
|
|
32
|
+
path: ""
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
[ChainTypes.DOGE]: [
|
|
36
|
+
{
|
|
37
|
+
address: accountWallet == null ? void 0 : accountWallet.dogeAddress,
|
|
38
|
+
publicKey: "",
|
|
39
|
+
subType: ChainTypes.DOGE,
|
|
40
|
+
path: ""
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
[ChainTypes.SOL]: [
|
|
44
|
+
{
|
|
45
|
+
address: accountWallet == null ? void 0 : accountWallet.solanaAddress,
|
|
46
|
+
publicKey: "",
|
|
47
|
+
subType: ChainTypes.SOL,
|
|
48
|
+
path: ""
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
[ChainTypes.TRON]: [
|
|
52
|
+
{
|
|
53
|
+
address: accountWallet == null ? void 0 : accountWallet.tronAddress,
|
|
54
|
+
publicKey: "",
|
|
55
|
+
subType: ChainTypes.TRON,
|
|
56
|
+
path: ""
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
[ChainTypes.BTC]: [
|
|
60
|
+
{
|
|
61
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2trAddressMain,
|
|
62
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2trPubKeyMain,
|
|
63
|
+
subType: "TAPROOT",
|
|
64
|
+
stage: "MAIN",
|
|
65
|
+
path: "m/86'/0'/0'/0/0"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2trAddressTest,
|
|
69
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2trPubKeyTest,
|
|
70
|
+
subType: "TAPROOT",
|
|
71
|
+
stage: "TEST",
|
|
72
|
+
path: "m/86'/1'/0'/0/0"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2shAddressMain,
|
|
76
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2shPubKeyMain,
|
|
77
|
+
subType: "NESTED_SEGWIT",
|
|
78
|
+
stage: "MAIN",
|
|
79
|
+
path: "m/49'/0'/0'/0/0"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2shAddressTest,
|
|
83
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2shPubKeyTest,
|
|
84
|
+
subType: "NESTED_SEGWIT",
|
|
85
|
+
stage: "TEST",
|
|
86
|
+
path: "m/49'/1'/0'/0/0"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhAddressMain,
|
|
90
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhPubKeyMain,
|
|
91
|
+
subType: "NATIVE_SEGWIT",
|
|
92
|
+
stage: "MAIN",
|
|
93
|
+
path: "m/84'/0'/0'/0/0"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhAddressTest,
|
|
97
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2wpkhPubKeyTest,
|
|
98
|
+
subType: "NATIVE_SEGWIT",
|
|
99
|
+
stage: "TEST",
|
|
100
|
+
path: "m/84'/0'/0'/0/0"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhAddressMain,
|
|
104
|
+
publicKey: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhPubKeyMain,
|
|
105
|
+
subType: "LEGACY",
|
|
106
|
+
stage: "MAIN",
|
|
107
|
+
path: "m/44'/0'/0'/0/0"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
address: accountWallet == null ? void 0 : accountWallet.bitcoinP2pkhAddressTest,
|
|
111
|
+
publicKey: accountWallet == null ? void 0 : 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 == null ? void 0 : accountWallet.suiAddress,
|
|
120
|
+
publicKey: "",
|
|
121
|
+
subType: ChainTypes.SUI,
|
|
122
|
+
path: ""
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
[ChainTypes.TON]: [
|
|
126
|
+
{
|
|
127
|
+
address: accountWallet == null ? void 0 : accountWallet.tonAddress,
|
|
128
|
+
publicKey: "",
|
|
129
|
+
subType: ChainTypes.TON,
|
|
130
|
+
path: ""
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
[ChainTypes.COSMOS]: [
|
|
134
|
+
{
|
|
135
|
+
address: accountWallet == null ? void 0 : accountWallet.cosmosAddress,
|
|
136
|
+
publicKey: "",
|
|
137
|
+
subType: ChainTypes.COSMOS,
|
|
138
|
+
path: ""
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
[ChainTypes.APTOS]: [
|
|
142
|
+
{
|
|
143
|
+
address: accountWallet == null ? void 0 : accountWallet.aptosAddress,
|
|
144
|
+
publicKey: "",
|
|
145
|
+
subType: ChainTypes.APTOS,
|
|
146
|
+
path: ""
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
id: user.accountID,
|
|
152
|
+
name: user.nickname,
|
|
153
|
+
type: AccountType.SOCIAL,
|
|
154
|
+
lastUsedTime: user.lastUsedTime,
|
|
155
|
+
addresses,
|
|
156
|
+
mnemonic: null,
|
|
157
|
+
addressIndex: 0,
|
|
158
|
+
isImported: false,
|
|
159
|
+
isBackedUp: false,
|
|
160
|
+
isLocked: false,
|
|
161
|
+
isFrozen: false
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
async getCurrent() {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
const chainType = this.chainType;
|
|
167
|
+
const account = await this.getAllAccounts();
|
|
168
|
+
const { address, publicKey, path, subType } = ((_b = (_a = account == null ? void 0 : account.addresses) == null ? void 0 : _a[chainType]) == null ? void 0 : _b[0]) || {};
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
subType,
|
|
172
|
+
address,
|
|
173
|
+
path,
|
|
174
|
+
publicKey,
|
|
175
|
+
type: account.type,
|
|
176
|
+
id: account.id
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
async signMessage(message) {
|
|
181
|
+
const currentAccounts = await this.getCurrent();
|
|
182
|
+
const chainType = this.chainType;
|
|
183
|
+
try {
|
|
184
|
+
const address = currentAccounts[0].address;
|
|
185
|
+
return await this.cubeSignService.signMessage(chainType, address, message);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error("Error signing message with CubeSignService:", error);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async signTypedData(typedData) {
|
|
192
|
+
const currentAccounts = await this.getCurrent();
|
|
193
|
+
const chainType = this.chainType;
|
|
194
|
+
try {
|
|
195
|
+
const address = currentAccounts[0].address;
|
|
196
|
+
return await this.cubeSignService.signTypedData(chainType, address, typedData);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error("Error signing typed data with CubeSignService:", error);
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//VersionedTransaction cannot through entirely to background by sendMessage
|
|
203
|
+
async signTransaction(unsignedTx) {
|
|
204
|
+
const currentAccounts = await this.getCurrent();
|
|
205
|
+
const chainType = this.chainType;
|
|
206
|
+
const address = currentAccounts[0].address;
|
|
207
|
+
try {
|
|
208
|
+
return await this.cubeSignService.signTransaction(chainType, address, unsignedTx);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error("Error signing transaction with CubeSignService:", error);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var SocialAccount = (accountData, chainConfig, tomoAppConfig) => {
|
|
216
|
+
const { chainType, chainId } = chainConfig;
|
|
217
|
+
const cubeAccountService = CubeAccountService.getInstance();
|
|
218
|
+
cubeAccountService.initCubeSignService();
|
|
219
|
+
const socialAccount = new CubeSocialAccount(chainConfig, accountData);
|
|
220
|
+
const CurrentService = ChainTypeServices[chainType];
|
|
221
|
+
if (!CurrentService) {
|
|
222
|
+
throw new Error(`ChainTypeServices not found for chainType: ${chainType}`);
|
|
223
|
+
}
|
|
224
|
+
const currentService = CurrentService.getInstance(chainType, socialAccount, tomoAppConfig);
|
|
225
|
+
currentService.wallet_switchEthereumChain([{ chainId }]);
|
|
226
|
+
return currentService;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export { SocialAccount };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tomo-inc/social-account-sdk",
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
|
+
"author": "tomo.inc",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --treeshake",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
24
|
+
"prepare": "pnpm build",
|
|
25
|
+
"lint": "eslint src/**/*.ts",
|
|
26
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
27
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@tomo-inc/wallet-utils": "workspace:*",
|
|
33
|
+
"@tomo-inc/oidc-auth": "workspace:*",
|
|
34
|
+
"@tomo-inc/cubist-wallet-sdk": "workspace:*",
|
|
35
|
+
"@tomo-inc/chains-service": "workspace:*"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/crypto-js": "^4.2.2",
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"@types/supertest": "^2.0.12",
|
|
41
|
+
"supertest": "^6.3.0",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"tsx": "^4.19.2",
|
|
44
|
+
"typescript": "^5.0.0",
|
|
45
|
+
"@vitest/browser": "^3.2.4",
|
|
46
|
+
"playwright": "^1.44.1",
|
|
47
|
+
"vitest": "^3.2.4"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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 };
|