-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathconfig.ts
More file actions
145 lines (128 loc) · 4.67 KB
/
Copy pathconfig.ts
File metadata and controls
145 lines (128 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Environment, ImmutableConfiguration } from '@imtbl/config';
import { createConfig, MultiRollupAPIConfiguration, multiRollupConfig } from '@imtbl/generated-clients';
import {
OidcConfiguration,
PassportModuleConfiguration,
PopupOverlayOptions,
} from '../types';
import { PassportError, PassportErrorType } from '../errors/passportError';
const validateConfiguration = <T>(
configuration: T,
requiredKeys: Array<keyof T>,
prefix?: string,
) => {
const missingKeys = requiredKeys
.map((key) => !configuration[key] && key)
.filter((n) => n)
.join(', ');
if (missingKeys !== '') {
const errorMessage = prefix
? `${prefix} - ${missingKeys} cannot be null`
: `${missingKeys} cannot be null`;
throw new PassportError(
errorMessage,
PassportErrorType.INVALID_CONFIGURATION,
);
}
};
export class PassportConfiguration {
readonly authenticationDomain: string;
readonly passportDomain: string;
readonly imxPublicApiDomain: string;
readonly magicPublishableApiKey: string;
readonly magicProviderId: string;
readonly magicTeeBasePath: string = 'https://tee.express.magiclabs.com';
readonly magicTeeTimeout: number = 6000;
readonly oidcConfiguration: OidcConfiguration;
readonly baseConfig: ImmutableConfiguration;
readonly zkEvmRpcUrl: string;
readonly relayerUrl: string;
readonly multiRollupConfig: MultiRollupAPIConfiguration;
readonly crossSdkBridgeEnabled: boolean;
readonly forceScwDeployBeforeMessageSignature: boolean;
readonly popupOverlayOptions: PopupOverlayOptions;
constructor({
baseConfig,
overrides,
crossSdkBridgeEnabled,
jsonRpcReferrer,
forceScwDeployBeforeMessageSignature,
popupOverlayOptions,
...oidcConfiguration
}: PassportModuleConfiguration) {
validateConfiguration(oidcConfiguration, [
'clientId',
'redirectUri',
]);
this.oidcConfiguration = oidcConfiguration;
this.baseConfig = baseConfig;
this.crossSdkBridgeEnabled = crossSdkBridgeEnabled || false;
this.forceScwDeployBeforeMessageSignature = forceScwDeployBeforeMessageSignature || false;
this.popupOverlayOptions = popupOverlayOptions || {
disableGenericPopupOverlay: false,
disableBlockedPopupOverlay: false,
};
if (overrides) {
validateConfiguration(
overrides,
[
'authenticationDomain',
'passportDomain',
'magicPublishableApiKey',
'magicProviderId',
'zkEvmRpcUrl',
'relayerUrl',
'imxPublicApiDomain',
'indexerMrBasePath',
'orderBookMrBasePath',
'passportMrBasePath',
],
'overrides',
);
this.authenticationDomain = overrides.authenticationDomain;
this.passportDomain = overrides.passportDomain;
this.imxPublicApiDomain = overrides.imxPublicApiDomain;
this.magicPublishableApiKey = overrides.magicPublishableApiKey;
this.magicProviderId = overrides.magicProviderId;
this.zkEvmRpcUrl = overrides.zkEvmRpcUrl;
this.relayerUrl = overrides.relayerUrl;
this.multiRollupConfig = {
indexer: createConfig({
basePath: overrides.indexerMrBasePath,
}),
orderBook: createConfig({
basePath: overrides.orderBookMrBasePath,
}),
passport: createConfig({
basePath: overrides.passportMrBasePath,
}),
};
} else {
switch (baseConfig.environment) {
case Environment.PRODUCTION: {
this.authenticationDomain = 'https://auth.immutable.com';
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
this.passportDomain = 'https://passport.immutable.com';
this.imxPublicApiDomain = 'https://api.immutable.com';
this.zkEvmRpcUrl = 'https://rpc.immutable.com';
this.relayerUrl = 'https://api.immutable.com/relayer-mr';
this.multiRollupConfig = multiRollupConfig.getProduction();
break;
}
case Environment.SANDBOX:
default: {
this.authenticationDomain = 'https://auth.immutable.com';
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
this.passportDomain = 'https://passport.sandbox.immutable.com';
this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
this.multiRollupConfig = multiRollupConfig.getSandbox();
break;
}
}
}
}
}