@imtbl/sdk 0.0.1-alpha.3 → 0.1.1
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/README.md +28 -0
- package/dist/{starkex.d.ts → immutablex_client.d.ts} +670 -10
- package/dist/immutablex_client.js +510 -0
- package/dist/index.cjs +535 -1762
- package/dist/index.d.ts +391 -14979
- package/dist/index.js +533 -1761
- package/dist/passport.d.ts +6 -15
- package/dist/passport.js +34 -9
- package/package.json +22 -44
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_sdk.d.ts +0 -692
- package/dist/checkout_sdk.js +0 -553
- package/dist/checkout_widgets.d.ts +0 -14447
- package/dist/checkout_widgets.js +0 -198
- package/dist/provider.d.ts +0 -962
- package/dist/provider.js +0 -1139
- package/dist/starkex.js +0 -58
- /package/dist/{base.d.ts → config.d.ts} +0 -0
- /package/dist/{base.js → config.js} +0 -0
package/dist/passport.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare enum PassportErrorType {
|
|
|
3
3
|
INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
|
|
4
4
|
WALLET_CONNECTION_ERROR = "WALLET_CONNECTION_ERROR",
|
|
5
5
|
NOT_LOGGED_IN_ERROR = "NOT_LOGGED_IN_ERROR",
|
|
6
|
+
SILENT_LOGIN_ERROR = "SILENT_LOGIN_ERROR",
|
|
6
7
|
REFRESH_TOKEN_ERROR = "REFRESH_TOKEN_ERROR",
|
|
7
8
|
USER_REGISTRATION_ERROR = "USER_REGISTRATION_ERROR",
|
|
8
9
|
LOGOUT_ERROR = "LOGOUT_ERROR",
|
|
@@ -712,25 +713,15 @@ declare class Passport {
|
|
|
712
713
|
private magicAdapter;
|
|
713
714
|
private readonly config;
|
|
714
715
|
constructor(passportModuleConfiguration: PassportModuleConfiguration);
|
|
716
|
+
private getImxProvider;
|
|
717
|
+
connectImxSilent(): Promise<IMXProvider | null>;
|
|
715
718
|
connectImx(): Promise<IMXProvider>;
|
|
716
719
|
loginCallback(): Promise<void>;
|
|
717
720
|
logout(): Promise<void>;
|
|
718
|
-
getUserInfo(): Promise<UserProfile>;
|
|
721
|
+
getUserInfo(): Promise<UserProfile | undefined>;
|
|
719
722
|
getIdToken(): Promise<string | undefined>;
|
|
720
|
-
getAccessToken(): Promise<string>;
|
|
723
|
+
getAccessToken(): Promise<string | undefined>;
|
|
721
724
|
private registerUser;
|
|
722
725
|
}
|
|
723
726
|
|
|
724
|
-
|
|
725
|
-
readonly network: Networks;
|
|
726
|
-
readonly authenticationDomain: string;
|
|
727
|
-
readonly passportDomain: string;
|
|
728
|
-
readonly magicPublishableApiKey: string;
|
|
729
|
-
readonly magicProviderId: string;
|
|
730
|
-
readonly imxApiBasePath: string;
|
|
731
|
-
readonly oidcConfiguration: OidcConfiguration;
|
|
732
|
-
readonly baseConfig: ImmutableConfiguration;
|
|
733
|
-
constructor({ baseConfig, overrides, ...oidcConfiguration }: PassportModuleConfiguration);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
export { Passport, PassportConfiguration, PassportError };
|
|
727
|
+
export { Passport, PassportError, PassportModuleConfiguration };
|
package/dist/passport.js
CHANGED
|
@@ -79,6 +79,7 @@ var PassportErrorType;
|
|
|
79
79
|
PassportErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
80
80
|
PassportErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
81
81
|
PassportErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
82
|
+
PassportErrorType["SILENT_LOGIN_ERROR"] = "SILENT_LOGIN_ERROR";
|
|
82
83
|
PassportErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
83
84
|
PassportErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
84
85
|
PassportErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
@@ -160,6 +161,7 @@ class AuthManager {
|
|
|
160
161
|
mapOidcUserToDomainModel = (oidcUser) => {
|
|
161
162
|
const passport = oidcUser.profile?.passport;
|
|
162
163
|
return {
|
|
164
|
+
expired: oidcUser.expired,
|
|
163
165
|
idToken: oidcUser.id_token,
|
|
164
166
|
accessToken: oidcUser.access_token,
|
|
165
167
|
refreshToken: oidcUser.refresh_token,
|
|
@@ -173,7 +175,7 @@ class AuthManager {
|
|
|
173
175
|
};
|
|
174
176
|
async login() {
|
|
175
177
|
return withPassportError(async () => {
|
|
176
|
-
const popupWindowFeatures = { width:
|
|
178
|
+
const popupWindowFeatures = { width: 410, height: 450 };
|
|
177
179
|
const oidcUser = await this.userManager.signinPopup({
|
|
178
180
|
popupWindowFeatures,
|
|
179
181
|
});
|
|
@@ -186,11 +188,24 @@ class AuthManager {
|
|
|
186
188
|
async logout() {
|
|
187
189
|
return withPassportError(async () => this.userManager.signoutRedirect(), PassportErrorType.LOGOUT_ERROR);
|
|
188
190
|
}
|
|
191
|
+
async loginSilent() {
|
|
192
|
+
return withPassportError(async () => {
|
|
193
|
+
const existedUser = await this.getUser();
|
|
194
|
+
if (!existedUser) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const oidcUser = await this.userManager.signinSilent();
|
|
198
|
+
if (!oidcUser) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
202
|
+
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
203
|
+
}
|
|
189
204
|
async getUser() {
|
|
190
205
|
return withPassportError(async () => {
|
|
191
206
|
const oidcUser = await this.userManager.getUser();
|
|
192
207
|
if (!oidcUser) {
|
|
193
|
-
|
|
208
|
+
return null;
|
|
194
209
|
}
|
|
195
210
|
return this.mapOidcUserToDomainModel(oidcUser);
|
|
196
211
|
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
@@ -848,9 +863,8 @@ class Passport {
|
|
|
848
863
|
this.authManager = new AuthManager(this.config);
|
|
849
864
|
this.magicAdapter = new MagicAdapter(this.config);
|
|
850
865
|
}
|
|
851
|
-
async
|
|
852
|
-
|
|
853
|
-
if (!user.idToken) {
|
|
866
|
+
async getImxProvider(user) {
|
|
867
|
+
if (!user || !user.idToken) {
|
|
854
868
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
855
869
|
}
|
|
856
870
|
const provider = await this.magicAdapter.login(user.idToken);
|
|
@@ -871,6 +885,17 @@ class Passport {
|
|
|
871
885
|
passportConfig: this.config,
|
|
872
886
|
});
|
|
873
887
|
}
|
|
888
|
+
async connectImxSilent() {
|
|
889
|
+
const user = await this.authManager.loginSilent();
|
|
890
|
+
if (!user) {
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
return this.getImxProvider(user);
|
|
894
|
+
}
|
|
895
|
+
async connectImx() {
|
|
896
|
+
const user = await this.authManager.login();
|
|
897
|
+
return this.getImxProvider(user);
|
|
898
|
+
}
|
|
874
899
|
async loginCallback() {
|
|
875
900
|
return this.authManager.loginCallback();
|
|
876
901
|
}
|
|
@@ -879,15 +904,15 @@ class Passport {
|
|
|
879
904
|
}
|
|
880
905
|
async getUserInfo() {
|
|
881
906
|
const user = await this.authManager.getUser();
|
|
882
|
-
return user
|
|
907
|
+
return user?.profile;
|
|
883
908
|
}
|
|
884
909
|
async getIdToken() {
|
|
885
910
|
const user = await this.authManager.getUser();
|
|
886
|
-
return user
|
|
911
|
+
return user?.idToken;
|
|
887
912
|
}
|
|
888
913
|
async getAccessToken() {
|
|
889
914
|
const user = await this.authManager.getUser();
|
|
890
|
-
return user
|
|
915
|
+
return user?.accessToken;
|
|
891
916
|
}
|
|
892
917
|
async registerUser(userAdminKeySigner, starkSigner, jwt) {
|
|
893
918
|
const configuration = new Configuration({
|
|
@@ -907,4 +932,4 @@ class Passport {
|
|
|
907
932
|
}
|
|
908
933
|
}
|
|
909
934
|
|
|
910
|
-
export { Passport,
|
|
935
|
+
export { Passport, PassportError };
|
package/package.json
CHANGED
|
@@ -1,53 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/sdk",
|
|
3
3
|
"description": "Immutable Unified SDK",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@biom3/design-tokens": "0.1.4-beta",
|
|
9
|
-
"@biom3/react": "^0.2.4-beta",
|
|
10
8
|
"@ethersproject/providers": "^5.7.2",
|
|
11
9
|
"@imtbl/core-sdk": "^1.1.1-alpha.1",
|
|
12
10
|
"@magic-ext/oidc": "^1.0.1",
|
|
13
11
|
"@metamask/detect-provider": "^2.0.0",
|
|
14
|
-
"@rollup/plugin-replace": "^5.0.2",
|
|
15
|
-
"@swc/helpers": "~0.5.0",
|
|
16
|
-
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
17
|
-
"@typescript-eslint/parser": "^5.57.1",
|
|
18
|
-
"@uniswap/router-sdk": "^1.4.0",
|
|
19
|
-
"@uniswap/swap-router-contracts": "^1.3.0",
|
|
20
|
-
"@uniswap/v3-core": "^1.0.1",
|
|
21
|
-
"@uniswap/v3-periphery": "^1.4.3",
|
|
22
|
-
"@uniswap/v3-sdk": "^3.9.0",
|
|
23
12
|
"axios": "^1.3.5",
|
|
24
|
-
"compression": "^1.7.4",
|
|
25
|
-
"dotenv": "^16.0.3",
|
|
26
13
|
"eslint": "^8.37.0",
|
|
27
14
|
"ethers": "^5.7.2",
|
|
28
|
-
"express": "^4.17.1",
|
|
29
|
-
"express-formidable": "^1.2.0",
|
|
30
|
-
"helmet": "^4.2.0",
|
|
31
15
|
"magic-sdk": "^13.3.1",
|
|
32
16
|
"oidc-client-ts": "^2.2.1",
|
|
33
|
-
"pino": "^8.11.0",
|
|
34
|
-
"pino-http": "^8.3.3",
|
|
35
17
|
"react": "^18.2.0",
|
|
36
|
-
"react-dom": "^18.2.0"
|
|
37
|
-
"react-router-dom": "^6.10.0",
|
|
38
|
-
"rxjs": "^7.8.0",
|
|
39
|
-
"tsc-watch": "^6.0.0"
|
|
18
|
+
"react-dom": "^18.2.0"
|
|
40
19
|
},
|
|
41
20
|
"devDependencies": {
|
|
42
21
|
"@imtbl/checkout-sdk-web": "0.0.0",
|
|
43
22
|
"@imtbl/checkout-ui-types": "0.0.0",
|
|
44
23
|
"@imtbl/config": "0.0.0",
|
|
24
|
+
"@imtbl/immutablex-client": "0.0.0",
|
|
45
25
|
"@imtbl/passport": "0.0.0",
|
|
46
26
|
"@imtbl/provider": "0.0.0",
|
|
47
|
-
"@imtbl/starkex": "0.0.0",
|
|
48
27
|
"@rollup/plugin-commonjs": "^24.0.1",
|
|
49
28
|
"@rollup/plugin-json": "^6.0.0",
|
|
50
29
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
30
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
51
31
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
52
32
|
"@yarnpkg/cli": "3.5.0",
|
|
53
33
|
"@yarnpkg/core": "3.5.0",
|
|
@@ -58,33 +38,26 @@
|
|
|
58
38
|
"typescript": "^4.9.5"
|
|
59
39
|
},
|
|
60
40
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
41
|
+
"node": ">=16.11.0"
|
|
62
42
|
},
|
|
63
43
|
"exports": {
|
|
64
44
|
"./package.json": "./package.json",
|
|
65
45
|
".": {
|
|
66
|
-
"types": "./dist/
|
|
67
|
-
"import": "./dist/
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": "./dist/index.js",
|
|
48
|
+
"require": "./dist/index.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./config": {
|
|
51
|
+
"types": "./dist/config.d.ts",
|
|
52
|
+
"import": "./dist/config.js"
|
|
68
53
|
},
|
|
69
|
-
"./
|
|
70
|
-
"types": "./dist/
|
|
71
|
-
"import": "./dist/
|
|
54
|
+
"./immutablex_client": {
|
|
55
|
+
"types": "./dist/immutablex_client.d.ts",
|
|
56
|
+
"import": "./dist/immutablex_client.js"
|
|
72
57
|
},
|
|
73
58
|
"./passport": {
|
|
74
59
|
"types": "./dist/passport.d.ts",
|
|
75
60
|
"import": "./dist/passport.js"
|
|
76
|
-
},
|
|
77
|
-
"./provider": {
|
|
78
|
-
"types": "./dist/provider.d.ts",
|
|
79
|
-
"import": "./dist/provider.js"
|
|
80
|
-
},
|
|
81
|
-
"./checkout_sdk": {
|
|
82
|
-
"types": "./dist/checkout_sdk.d.ts",
|
|
83
|
-
"import": "./dist/checkout_sdk.js"
|
|
84
|
-
},
|
|
85
|
-
"./checkout_widgets": {
|
|
86
|
-
"types": "./dist/checkout_widgets.d.ts",
|
|
87
|
-
"import": "./dist/checkout_widgets.js"
|
|
88
61
|
}
|
|
89
62
|
},
|
|
90
63
|
"files": [
|
|
@@ -93,13 +66,18 @@
|
|
|
93
66
|
"homepage": "https://github.com/immutable/ts-immutable-sdk#readme",
|
|
94
67
|
"license": "Apache-2.0",
|
|
95
68
|
"main": "./dist/index.cjs",
|
|
69
|
+
"module": "./dist/index.js",
|
|
96
70
|
"repository": "immutable/ts-immutable-sdk.git",
|
|
97
71
|
"scripts": {
|
|
98
|
-
"build": "yarn packageList && yarn updateDependencies && rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
72
|
+
"build": "yarn packageList && yarn updateDependencies && yarn regenModules && rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
73
|
+
"build:only": "rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
74
|
+
"generateIndex": "node scripts/generateIndex.js",
|
|
99
75
|
"lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
|
|
100
76
|
"packageList": "./scripts/generate-package-list.sh",
|
|
77
|
+
"regenModules": "yarn generateIndex && yarn updateExports",
|
|
101
78
|
"typecheck": "tsc --noEmit --jsx preserve",
|
|
102
|
-
"updateDependencies": "node ./scripts/updateDependencies.js"
|
|
79
|
+
"updateDependencies": "yarn packageList && node ./scripts/updateDependencies.js",
|
|
80
|
+
"updateExports": "node scripts/updateExports.js"
|
|
103
81
|
},
|
|
104
82
|
"type": "module",
|
|
105
83
|
"types": "./dist/index.d.ts"
|