@imtbl/sdk 0.0.1-alpha.3 → 0.1.0-alpha
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/checkout_sdk.d.ts +247 -7
- package/dist/checkout_sdk.js +147 -91
- package/dist/checkout_widgets.d.ts +13 -2
- package/dist/checkout_widgets.js +4 -2
- package/dist/{starkex.d.ts → immutablex_client.d.ts} +670 -10
- package/dist/immutablex_client.js +510 -0
- package/dist/index.cjs +2359 -1820
- package/dist/index.d.ts +644 -41
- package/dist/index.js +2344 -1811
- package/dist/passport.d.ts +5 -2
- package/dist/passport.js +33 -8
- package/dist/provider.d.ts +2 -2
- package/dist/provider.js +43 -43
- package/package.json +22 -32
- package/dist/browser/checkout.js +0 -2
- 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,12 +713,14 @@ 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
|
|
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({
|
package/dist/provider.d.ts
CHANGED
|
@@ -908,7 +908,7 @@ interface IMXProvider {
|
|
|
908
908
|
declare class GenericIMXProvider implements IMXProvider {
|
|
909
909
|
private readonly config;
|
|
910
910
|
private readonly signers;
|
|
911
|
-
constructor(config: ProviderConfiguration$1, ethSigner: Signer,
|
|
911
|
+
constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
|
|
912
912
|
getAddress(): Promise<string>;
|
|
913
913
|
registerOffchain(): Promise<RegisterUserResponse>;
|
|
914
914
|
batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
|
|
@@ -925,7 +925,7 @@ declare class GenericIMXProvider implements IMXProvider {
|
|
|
925
925
|
|
|
926
926
|
declare class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
927
927
|
private static imxSigner;
|
|
928
|
-
constructor(config: ProviderConfiguration$1, ethSigner: Signer,
|
|
928
|
+
constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
|
|
929
929
|
static connect(config: ProviderConfiguration$1): Promise<MetaMaskIMXProvider>;
|
|
930
930
|
static disconnect(): Promise<void>;
|
|
931
931
|
static signMessage(message: string): Promise<string>;
|
package/dist/provider.js
CHANGED
|
@@ -91,7 +91,7 @@ async function validateChain(signer, config) {
|
|
|
91
91
|
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
async function transfer({ signers: { ethSigner,
|
|
94
|
+
async function transfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
95
95
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
96
96
|
const ethAddress = await ethSigner.getAddress();
|
|
97
97
|
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
@@ -106,7 +106,7 @@ async function transfer({ signers: { ethSigner, starkExSigner }, request, config
|
|
|
106
106
|
});
|
|
107
107
|
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
108
108
|
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
109
|
-
const starkSignature = await
|
|
109
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
110
110
|
const transferSigningParams = {
|
|
111
111
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
112
112
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
@@ -131,7 +131,7 @@ async function transfer({ signers: { ethSigner, starkExSigner }, request, config
|
|
|
131
131
|
transfer_id: response?.data.transfer_id,
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
async function batchTransfer({ signers: { ethSigner,
|
|
134
|
+
async function batchTransfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
135
135
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
136
136
|
const ethAddress = await ethSigner.getAddress();
|
|
137
137
|
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
@@ -159,7 +159,7 @@ async function batchTransfer({ signers: { ethSigner, starkExSigner }, request, c
|
|
|
159
159
|
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
160
160
|
const requests = [];
|
|
161
161
|
for (const resp of signableResult.data.signable_responses) {
|
|
162
|
-
const starkSignature = await
|
|
162
|
+
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
163
163
|
const req = {
|
|
164
164
|
sender_vault_id: resp.sender_vault_id,
|
|
165
165
|
receiver_stark_key: resp.receiver_stark_key,
|
|
@@ -207,7 +207,7 @@ async function createOrder({ signers, request, config, }) {
|
|
|
207
207
|
});
|
|
208
208
|
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
209
209
|
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
210
|
-
const starkSignature = await signers.
|
|
210
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
211
211
|
const resp = getSignableOrderResponse.data;
|
|
212
212
|
const orderParams = {
|
|
213
213
|
createOrderRequest: {
|
|
@@ -241,7 +241,7 @@ async function cancelOrder({ signers, request, config, }) {
|
|
|
241
241
|
});
|
|
242
242
|
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
243
243
|
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
244
|
-
const starkSignature = await signers.
|
|
244
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
245
245
|
const ethAddress = await signers.ethSigner.getAddress();
|
|
246
246
|
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
247
247
|
id: request.order_id.toString(),
|
|
@@ -262,7 +262,7 @@ async function registerOffchain(signers, config) {
|
|
|
262
262
|
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
263
263
|
const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
|
|
264
264
|
const userAddress = await signers.ethSigner.getAddress();
|
|
265
|
-
const starkPublicKey = await signers.
|
|
265
|
+
const starkPublicKey = await signers.starkSigner.getAddress();
|
|
266
266
|
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
267
267
|
getSignableRegistrationRequest: {
|
|
268
268
|
ether_key: userAddress,
|
|
@@ -271,7 +271,7 @@ async function registerOffchain(signers, config) {
|
|
|
271
271
|
});
|
|
272
272
|
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
273
273
|
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
274
|
-
const starkSignature = await signers.
|
|
274
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
275
275
|
const registeredUser = await usersApi.registerUser({
|
|
276
276
|
registerUserRequest: {
|
|
277
277
|
eth_signature: ethSignature,
|
|
@@ -314,7 +314,7 @@ const assertIsDefined = (value) => {
|
|
|
314
314
|
throw new Error('undefined field exception');
|
|
315
315
|
};
|
|
316
316
|
async function prepareWithdrawalAction(params) {
|
|
317
|
-
const { signers: { ethSigner,
|
|
317
|
+
const { signers: { ethSigner, starkSigner }, type, config, } = params;
|
|
318
318
|
await validateChain(ethSigner, params.config);
|
|
319
319
|
const withdrawalsApi = new WithdrawalsApi(config.apiConfiguration);
|
|
320
320
|
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
@@ -326,7 +326,7 @@ async function prepareWithdrawalAction(params) {
|
|
|
326
326
|
},
|
|
327
327
|
});
|
|
328
328
|
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
329
|
-
const starkSignature = await
|
|
329
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
330
330
|
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
331
331
|
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
332
332
|
createWithdrawalRequest: {
|
|
@@ -359,8 +359,8 @@ async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
|
359
359
|
|
|
360
360
|
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
361
361
|
const etherKey = await ethSigner.getAddress();
|
|
362
|
-
const
|
|
363
|
-
const usersApi = new UsersApi(
|
|
362
|
+
const imxConfig = config.immutableXConfig;
|
|
363
|
+
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
364
364
|
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
365
365
|
const contract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
366
366
|
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
@@ -373,8 +373,8 @@ async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config
|
|
|
373
373
|
}
|
|
374
374
|
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
375
375
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
376
|
-
const
|
|
377
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC20',
|
|
376
|
+
const imxConfig = config.immutableXConfig;
|
|
377
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC20', imxConfig, {
|
|
378
378
|
token_address: token.tokenAddress,
|
|
379
379
|
});
|
|
380
380
|
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
@@ -387,7 +387,7 @@ async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token,
|
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
389
|
else {
|
|
390
|
-
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey,
|
|
390
|
+
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
|
|
@@ -410,8 +410,8 @@ function getMintingBlob(token) {
|
|
|
410
410
|
return encUtils.sanitizeHex(encUtils.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
411
411
|
}
|
|
412
412
|
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
413
|
-
const
|
|
414
|
-
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721',
|
|
413
|
+
const imxConfig = config.immutableXConfig;
|
|
414
|
+
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', imxConfig, {
|
|
415
415
|
id: token.data.id,
|
|
416
416
|
token_address: token.data.tokenAddress,
|
|
417
417
|
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
@@ -419,10 +419,10 @@ async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token
|
|
|
419
419
|
const mintingBlob = getMintingBlob(token);
|
|
420
420
|
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
421
421
|
if (!isRegistered) {
|
|
422
|
-
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob,
|
|
422
|
+
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
423
423
|
}
|
|
424
424
|
else {
|
|
425
|
-
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob,
|
|
425
|
+
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
@@ -439,25 +439,25 @@ async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, token
|
|
|
439
439
|
return ethSigner.sendTransaction(populatedTransaction);
|
|
440
440
|
}
|
|
441
441
|
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
442
|
-
const
|
|
443
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC721',
|
|
442
|
+
const imxConfig = config.immutableXConfig;
|
|
443
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC721', imxConfig, {
|
|
444
444
|
token_id: token.tokenId,
|
|
445
445
|
token_address: token.tokenAddress,
|
|
446
446
|
});
|
|
447
447
|
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
448
448
|
if (!isRegistered) {
|
|
449
|
-
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId,
|
|
449
|
+
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
450
450
|
}
|
|
451
451
|
else {
|
|
452
|
-
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId,
|
|
452
|
+
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
456
456
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
457
457
|
const tokenAddress = token.tokenAddress;
|
|
458
458
|
const tokenId = token.tokenId;
|
|
459
|
-
const
|
|
460
|
-
const mintsApi = new MintsApi(
|
|
459
|
+
const imxConfig = config.immutableXConfig;
|
|
460
|
+
const mintsApi = new MintsApi(imxConfig.apiConfiguration);
|
|
461
461
|
return await mintsApi
|
|
462
462
|
.getMintableTokenDetailsByClientTokenId({
|
|
463
463
|
tokenAddress,
|
|
@@ -495,14 +495,14 @@ async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config)
|
|
|
495
495
|
}
|
|
496
496
|
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
497
497
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
498
|
-
const
|
|
499
|
-
const assetType = await getEncodeAssetInfo('asset', 'ETH',
|
|
498
|
+
const imxConfig = config.immutableXConfig;
|
|
499
|
+
const assetType = await getEncodeAssetInfo('asset', 'ETH', imxConfig);
|
|
500
500
|
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
501
501
|
if (!isRegistered) {
|
|
502
|
-
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey,
|
|
502
|
+
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
503
503
|
}
|
|
504
504
|
else {
|
|
505
|
-
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey,
|
|
505
|
+
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
|
|
@@ -534,7 +534,7 @@ async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, toke
|
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
-
async function createTrade({ signers: { ethSigner,
|
|
537
|
+
async function createTrade({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
538
538
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
539
539
|
const ethAddress = await ethSigner.getAddress();
|
|
540
540
|
const tradesApi = new TradesApi(config.immutableXConfig.apiConfiguration);
|
|
@@ -547,7 +547,7 @@ async function createTrade({ signers: { ethSigner, starkExSigner }, request, con
|
|
|
547
547
|
});
|
|
548
548
|
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
549
549
|
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
550
|
-
const starkSignature = await
|
|
550
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
551
551
|
const createTradeResponse = await tradesApi.createTrade({
|
|
552
552
|
createTradeRequest: {
|
|
553
553
|
amount_buy: signableResult.data.amount_buy,
|
|
@@ -578,10 +578,10 @@ async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
|
578
578
|
decimals: 18,
|
|
579
579
|
};
|
|
580
580
|
const amount = parseUnits(deposit.amount, 'wei');
|
|
581
|
-
const
|
|
582
|
-
const depositsApi = new DepositsApi(
|
|
583
|
-
const encodingApi = new EncodingApi(
|
|
584
|
-
const usersApi = new UsersApi(
|
|
581
|
+
const imxConfig = config.immutableXConfig;
|
|
582
|
+
const depositsApi = new DepositsApi(imxConfig.apiConfiguration);
|
|
583
|
+
const encodingApi = new EncodingApi(imxConfig.apiConfiguration);
|
|
584
|
+
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
585
585
|
const getSignableDepositRequest = {
|
|
586
586
|
user,
|
|
587
587
|
token: {
|
|
@@ -606,10 +606,10 @@ async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
|
606
606
|
const vaultId = signableDepositResult.data.vault_id;
|
|
607
607
|
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
608
608
|
if (!isRegistered) {
|
|
609
|
-
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId,
|
|
609
|
+
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig, usersApi);
|
|
610
610
|
}
|
|
611
611
|
else {
|
|
612
|
-
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId,
|
|
612
|
+
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig);
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
@@ -781,7 +781,7 @@ async function exchangeTransfer({ signers, request, config, }) {
|
|
|
781
781
|
});
|
|
782
782
|
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
783
783
|
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
784
|
-
const starkSignature = await signers.
|
|
784
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
785
785
|
const transferSigningParams = {
|
|
786
786
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
787
787
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
@@ -811,9 +811,9 @@ async function exchangeTransfer({ signers, request, config, }) {
|
|
|
811
811
|
class GenericIMXProvider {
|
|
812
812
|
config;
|
|
813
813
|
signers;
|
|
814
|
-
constructor(config, ethSigner,
|
|
814
|
+
constructor(config, ethSigner, starkSigner) {
|
|
815
815
|
this.config = config;
|
|
816
|
-
this.signers = { ethSigner,
|
|
816
|
+
this.signers = { ethSigner, starkSigner };
|
|
817
817
|
}
|
|
818
818
|
async getAddress() {
|
|
819
819
|
return await this.signers.ethSigner.getAddress();
|
|
@@ -872,7 +872,7 @@ class GenericIMXProvider {
|
|
|
872
872
|
});
|
|
873
873
|
}
|
|
874
874
|
async isRegisteredOnchain() {
|
|
875
|
-
const starkPublicKey = await this.signers.
|
|
875
|
+
const starkPublicKey = await this.signers.starkSigner.getAddress();
|
|
876
876
|
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
877
877
|
}
|
|
878
878
|
prepareWithdrawal(request) {
|
|
@@ -1083,8 +1083,8 @@ const withProviderError = async (fn, customError) => {
|
|
|
1083
1083
|
|
|
1084
1084
|
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
1085
1085
|
static imxSigner;
|
|
1086
|
-
constructor(config, ethSigner,
|
|
1087
|
-
super(config, ethSigner,
|
|
1086
|
+
constructor(config, ethSigner, starkSigner) {
|
|
1087
|
+
super(config, ethSigner, starkSigner);
|
|
1088
1088
|
}
|
|
1089
1089
|
static async connect(config) {
|
|
1090
1090
|
return await withProviderError(async () => {
|
package/package.json
CHANGED
|
@@ -1,53 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/sdk",
|
|
3
3
|
"description": "Immutable Unified SDK",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0-alpha",
|
|
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,17 +38,22 @@
|
|
|
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",
|
|
@@ -93,13 +78,18 @@
|
|
|
93
78
|
"homepage": "https://github.com/immutable/ts-immutable-sdk#readme",
|
|
94
79
|
"license": "Apache-2.0",
|
|
95
80
|
"main": "./dist/index.cjs",
|
|
81
|
+
"module": "./dist/index.js",
|
|
96
82
|
"repository": "immutable/ts-immutable-sdk.git",
|
|
97
83
|
"scripts": {
|
|
98
|
-
"build": "yarn packageList && yarn updateDependencies && rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
84
|
+
"build": "yarn packageList && yarn updateDependencies && yarn regenModules && rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
85
|
+
"build:only": "rm -rf dist && NODE_ENV=production rollup --config rollup.config.js && rm -rf dist/types",
|
|
86
|
+
"generateIndex": "node scripts/generateIndex.js",
|
|
99
87
|
"lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
|
|
100
88
|
"packageList": "./scripts/generate-package-list.sh",
|
|
89
|
+
"regenModules": "yarn generateIndex && yarn updateExports",
|
|
101
90
|
"typecheck": "tsc --noEmit --jsx preserve",
|
|
102
|
-
"updateDependencies": "node ./scripts/updateDependencies.js"
|
|
91
|
+
"updateDependencies": "yarn packageList && node ./scripts/updateDependencies.js",
|
|
92
|
+
"updateExports": "node scripts/updateExports.js"
|
|
103
93
|
},
|
|
104
94
|
"type": "module",
|
|
105
95
|
"types": "./dist/index.d.ts"
|