@imtbl/sdk 0.28.4-alpha.2 → 0.28.5
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/dist/blockchain_data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +18 -1
- package/dist/checkout_sdk.js +25 -25
- package/dist/checkout_widgets.d.ts +7 -1
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +12 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +95 -46
- package/dist/index.d.ts +19 -1
- package/dist/index.js +96 -47
- package/dist/passport.d.ts +7 -1
- package/dist/passport.js +48 -19
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +22 -2
- package/package.json +3 -3
package/dist/passport.js
CHANGED
|
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
|
|
|
2072
2072
|
}
|
|
2073
2073
|
|
|
2074
2074
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2075
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.
|
|
2075
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.5' };
|
|
2076
2076
|
const createConfig = ({ basePath, headers, }) => {
|
|
2077
2077
|
if (!basePath.trim()) {
|
|
2078
2078
|
throw Error('basePath can not be empty');
|
|
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2128
2128
|
chainID,
|
|
2129
2129
|
coreContractAddress,
|
|
2130
2130
|
registrationContractAddress,
|
|
2131
|
-
sdkVersion: 'ts-immutable-sdk-0.28.
|
|
2131
|
+
sdkVersion: 'ts-immutable-sdk-0.28.5',
|
|
2132
2132
|
});
|
|
2133
2133
|
/**
|
|
2134
2134
|
* Sets `sdkVersion` at the time of build
|
|
@@ -7056,39 +7056,63 @@ class AuthManager {
|
|
|
7056
7056
|
}
|
|
7057
7057
|
}
|
|
7058
7058
|
|
|
7059
|
+
const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
|
|
7060
|
+
const lazyDocumentReady = (initialiseFunction) => {
|
|
7061
|
+
const documentReadyPromise = () => new Promise((resolve) => {
|
|
7062
|
+
if (window.document.readyState === 'complete') {
|
|
7063
|
+
resolve();
|
|
7064
|
+
}
|
|
7065
|
+
else {
|
|
7066
|
+
const onReadyStateChange = () => {
|
|
7067
|
+
if (window.document.readyState === 'complete') {
|
|
7068
|
+
resolve();
|
|
7069
|
+
window.document.removeEventListener('readystatechange', onReadyStateChange);
|
|
7070
|
+
}
|
|
7071
|
+
};
|
|
7072
|
+
window.document.addEventListener('readystatechange', onReadyStateChange);
|
|
7073
|
+
}
|
|
7074
|
+
});
|
|
7075
|
+
return lazyLoad(documentReadyPromise, initialiseFunction);
|
|
7076
|
+
};
|
|
7077
|
+
|
|
7059
7078
|
class MagicAdapter {
|
|
7060
7079
|
config;
|
|
7061
|
-
|
|
7080
|
+
lazyMagicClient;
|
|
7062
7081
|
constructor(config) {
|
|
7063
7082
|
this.config = config;
|
|
7064
7083
|
if (typeof window !== 'undefined') {
|
|
7065
|
-
this.
|
|
7066
|
-
|
|
7084
|
+
this.lazyMagicClient = lazyDocumentReady(() => {
|
|
7085
|
+
const client = new Magic(this.config.magicPublishableApiKey, {
|
|
7086
|
+
extensions: [new OpenIdExtension()],
|
|
7087
|
+
network: this.config.network,
|
|
7088
|
+
});
|
|
7089
|
+
client.preload();
|
|
7090
|
+
return client;
|
|
7091
|
+
});
|
|
7067
7092
|
}
|
|
7068
7093
|
}
|
|
7094
|
+
get magicClient() {
|
|
7095
|
+
if (!this.lazyMagicClient) {
|
|
7096
|
+
throw new Error('Cannot perform this action outside of the browser');
|
|
7097
|
+
}
|
|
7098
|
+
return this.lazyMagicClient;
|
|
7099
|
+
}
|
|
7069
7100
|
async login(idToken) {
|
|
7070
7101
|
return withPassportError(async () => {
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
}
|
|
7074
|
-
await this.magicClient.openid.loginWithOIDC({
|
|
7102
|
+
const magicClient = await this.magicClient;
|
|
7103
|
+
await magicClient.openid.loginWithOIDC({
|
|
7075
7104
|
jwt: idToken,
|
|
7076
7105
|
providerId: this.config.magicProviderId,
|
|
7077
7106
|
});
|
|
7078
|
-
return
|
|
7107
|
+
return magicClient.rpcProvider;
|
|
7079
7108
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
7080
7109
|
}
|
|
7081
7110
|
async logout() {
|
|
7082
|
-
|
|
7083
|
-
|
|
7111
|
+
const magicClient = await this.magicClient;
|
|
7112
|
+
if (magicClient.user) {
|
|
7113
|
+
await magicClient.user.logout();
|
|
7084
7114
|
}
|
|
7085
7115
|
}
|
|
7086
|
-
initMagicClient() {
|
|
7087
|
-
return new Magic(this.config.magicPublishableApiKey, {
|
|
7088
|
-
extensions: [new OpenIdExtension()],
|
|
7089
|
-
network: this.config.network,
|
|
7090
|
-
});
|
|
7091
|
-
}
|
|
7092
7116
|
}
|
|
7093
7117
|
|
|
7094
7118
|
const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
@@ -7315,7 +7339,7 @@ var PassportEvents;
|
|
|
7315
7339
|
var Networks;
|
|
7316
7340
|
(function (Networks) {
|
|
7317
7341
|
Networks["PRODUCTION"] = "mainnet";
|
|
7318
|
-
Networks["SANDBOX"] = "
|
|
7342
|
+
Networks["SANDBOX"] = "sepolia";
|
|
7319
7343
|
})(Networks || (Networks = {}));
|
|
7320
7344
|
|
|
7321
7345
|
async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
@@ -7664,6 +7688,11 @@ class PassportImxProvider {
|
|
|
7664
7688
|
}
|
|
7665
7689
|
// TODO: Remove once implemented
|
|
7666
7690
|
// eslint-disable-next-line class-methods-use-this
|
|
7691
|
+
isRegisteredOffchain() {
|
|
7692
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7693
|
+
}
|
|
7694
|
+
// TODO: Remove once implemented
|
|
7695
|
+
// eslint-disable-next-line class-methods-use-this
|
|
7667
7696
|
isRegisteredOnchain() {
|
|
7668
7697
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7669
7698
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -833,6 +833,12 @@ interface IMXProvider {
|
|
|
833
833
|
* @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
|
|
834
834
|
*/
|
|
835
835
|
registerOffchain(): Promise<RegisterUserResponse>;
|
|
836
|
+
/**
|
|
837
|
+
* Checks if a User is registered off-chain
|
|
838
|
+
*
|
|
839
|
+
* @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
|
|
840
|
+
*/
|
|
841
|
+
isRegisteredOffchain(): Promise<boolean>;
|
|
836
842
|
/**
|
|
837
843
|
* Checks if a User is registered on-chain
|
|
838
844
|
*
|
|
@@ -910,6 +916,7 @@ declare class GenericIMXProvider implements IMXProvider {
|
|
|
910
916
|
private readonly signers;
|
|
911
917
|
constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
|
|
912
918
|
getAddress(): Promise<string>;
|
|
919
|
+
isRegisteredOffchain(): Promise<boolean>;
|
|
913
920
|
registerOffchain(): Promise<RegisterUserResponse>;
|
|
914
921
|
batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
|
|
915
922
|
cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
|
package/dist/provider.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Config, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
3
|
import * as encUtils from 'enc-utils';
|
|
4
|
+
import { AxiosError } from 'axios';
|
|
4
5
|
import { parseUnits } from '@ethersproject/units';
|
|
5
6
|
import { BigNumber } from '@ethersproject/bignumber';
|
|
6
7
|
import { ethers } from 'ethers';
|
|
7
8
|
import detectEthereumProvider from '@metamask/detect-provider';
|
|
8
|
-
import 'axios';
|
|
9
9
|
|
|
10
10
|
// used to sign message with L1 keys. Used for registration
|
|
11
11
|
function serializeEthSignature(sig) {
|
|
@@ -285,6 +285,22 @@ async function registerOffchain(signers, config) {
|
|
|
285
285
|
});
|
|
286
286
|
return registeredUser.data;
|
|
287
287
|
}
|
|
288
|
+
async function isRegisteredOffchain(ethAddress, config) {
|
|
289
|
+
try {
|
|
290
|
+
const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
|
|
291
|
+
const getUsersResult = await usersApi.getUsers({
|
|
292
|
+
user: ethAddress,
|
|
293
|
+
});
|
|
294
|
+
const { accounts } = getUsersResult.data;
|
|
295
|
+
return accounts?.length > 0;
|
|
296
|
+
}
|
|
297
|
+
catch (ex) {
|
|
298
|
+
if (ex instanceof AxiosError && ex.response?.status === 404) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
throw ex;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
288
304
|
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
289
305
|
await validateChain(ethSigner, config.immutableXConfig);
|
|
290
306
|
const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
@@ -820,7 +836,11 @@ class GenericIMXProvider {
|
|
|
820
836
|
this.signers = { ethSigner, starkSigner };
|
|
821
837
|
}
|
|
822
838
|
async getAddress() {
|
|
823
|
-
return
|
|
839
|
+
return this.signers.ethSigner.getAddress();
|
|
840
|
+
}
|
|
841
|
+
async isRegisteredOffchain() {
|
|
842
|
+
const ethAddress = await this.getAddress();
|
|
843
|
+
return isRegisteredOffchain(ethAddress, this.config);
|
|
824
844
|
}
|
|
825
845
|
registerOffchain() {
|
|
826
846
|
return registerOffchain(this.signers, this.config);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/sdk",
|
|
3
3
|
"description": "Immutable Unified SDK",
|
|
4
|
-
"version": "0.28.
|
|
4
|
+
"version": "0.28.5",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"browser": "./dist/index.browser.js",
|
|
7
7
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@ethersproject/wallet": "^5.7.0",
|
|
15
15
|
"@imtbl/core-sdk": "^2.4.0",
|
|
16
16
|
"@jest/globals": "^29.5.0",
|
|
17
|
-
"@magic-ext/oidc": "^
|
|
17
|
+
"@magic-ext/oidc": "^4.2.0",
|
|
18
18
|
"@metamask/detect-provider": "^2.0.0",
|
|
19
19
|
"@opensea/seaport-js": "2.0.7",
|
|
20
20
|
"@uniswap/router-sdk": "^1.4.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"enc-utils": "^3.0.0",
|
|
26
26
|
"ethers": "^5.7.2",
|
|
27
27
|
"jwt-decode": "^3.1.2",
|
|
28
|
-
"magic-sdk": "^
|
|
28
|
+
"magic-sdk": "^21.2.0",
|
|
29
29
|
"oidc-client-ts": "^2.2.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|