@imtbl/sdk 0.28.4 → 0.28.5-alpha.2
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/immutablex_client.js +1 -1
- package/dist/index.browser.js +10 -28
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +112 -20548
- package/dist/index.d.ts +57 -16734
- package/dist/index.js +123 -20557
- package/dist/passport.d.ts +7 -1
- package/dist/passport.js +67 -21
- package/dist/provider.d.ts +32 -27
- package/dist/provider.js +22 -2
- package/package.json +3 -11
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_sdk.d.ts +0 -12018
- package/dist/checkout_sdk.js +0 -25354
- package/dist/checkout_widgets.d.ts +0 -25583
- package/dist/checkout_widgets.js +0 -449
package/dist/passport.d.ts
CHANGED
|
@@ -9732,6 +9732,12 @@ interface IMXProvider {
|
|
|
9732
9732
|
* @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
|
|
9733
9733
|
*/
|
|
9734
9734
|
registerOffchain(): Promise<RegisterUserResponse>;
|
|
9735
|
+
/**
|
|
9736
|
+
* Checks if a User is registered off-chain
|
|
9737
|
+
*
|
|
9738
|
+
* @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
|
|
9739
|
+
*/
|
|
9740
|
+
isRegisteredOffchain(): Promise<boolean>;
|
|
9735
9741
|
/**
|
|
9736
9742
|
* Checks if a User is registered on-chain
|
|
9737
9743
|
*
|
|
@@ -10184,7 +10190,7 @@ type UserProfile = {
|
|
|
10184
10190
|
};
|
|
10185
10191
|
declare enum Networks {
|
|
10186
10192
|
PRODUCTION = "mainnet",
|
|
10187
|
-
SANDBOX = "
|
|
10193
|
+
SANDBOX = "sepolia"
|
|
10188
10194
|
}
|
|
10189
10195
|
interface OidcConfiguration {
|
|
10190
10196
|
clientId: string;
|
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-alpha.2' };
|
|
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-alpha.2',
|
|
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
|
+
});
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
get magicClient() {
|
|
7095
|
+
if (!this.lazyMagicClient) {
|
|
7096
|
+
throw new Error('Cannot perform this action outside of the browser');
|
|
7067
7097
|
}
|
|
7098
|
+
return this.lazyMagicClient;
|
|
7068
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
|
}
|
|
@@ -7757,7 +7786,17 @@ class PassportImxProviderFactory {
|
|
|
7757
7786
|
this.passportEventEmitter = passportEventEmitter;
|
|
7758
7787
|
}
|
|
7759
7788
|
async getProvider() {
|
|
7760
|
-
|
|
7789
|
+
let user = null;
|
|
7790
|
+
try {
|
|
7791
|
+
user = await this.authManager.loginSilent();
|
|
7792
|
+
}
|
|
7793
|
+
catch (e) {
|
|
7794
|
+
// eslint-disable-next-line no-console
|
|
7795
|
+
console.warn(e);
|
|
7796
|
+
}
|
|
7797
|
+
if (!user) {
|
|
7798
|
+
user = await this.authManager.login();
|
|
7799
|
+
}
|
|
7761
7800
|
return this.createProviderInstance(user);
|
|
7762
7801
|
}
|
|
7763
7802
|
async getProviderSilent() {
|
|
@@ -8812,7 +8851,14 @@ class Passport {
|
|
|
8812
8851
|
*/
|
|
8813
8852
|
async login(options) {
|
|
8814
8853
|
const { useCachedSession = false } = options || {};
|
|
8815
|
-
let user =
|
|
8854
|
+
let user = null;
|
|
8855
|
+
try {
|
|
8856
|
+
user = await this.authManager.loginSilent();
|
|
8857
|
+
}
|
|
8858
|
+
catch (error) {
|
|
8859
|
+
// eslint-disable-next-line no-console
|
|
8860
|
+
console.warn('loginSilent failed with error:', error);
|
|
8861
|
+
}
|
|
8816
8862
|
if (!user && !useCachedSession) {
|
|
8817
8863
|
user = await this.authManager.login();
|
|
8818
8864
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ProviderConfiguration as ProviderConfiguration$1 } from 'config';
|
|
2
|
-
|
|
3
1
|
declare type Bytes = ArrayLike<number>;
|
|
4
2
|
declare type BytesLike = Bytes | string;
|
|
5
3
|
interface Hexable {
|
|
@@ -833,6 +831,12 @@ interface IMXProvider {
|
|
|
833
831
|
* @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
|
|
834
832
|
*/
|
|
835
833
|
registerOffchain(): Promise<RegisterUserResponse>;
|
|
834
|
+
/**
|
|
835
|
+
* Checks if a User is registered off-chain
|
|
836
|
+
*
|
|
837
|
+
* @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
|
|
838
|
+
*/
|
|
839
|
+
isRegisteredOffchain(): Promise<boolean>;
|
|
836
840
|
/**
|
|
837
841
|
* Checks if a User is registered on-chain
|
|
838
842
|
*
|
|
@@ -905,31 +909,6 @@ interface IMXProvider {
|
|
|
905
909
|
completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
|
|
906
910
|
}
|
|
907
911
|
|
|
908
|
-
declare class GenericIMXProvider implements IMXProvider {
|
|
909
|
-
private readonly config;
|
|
910
|
-
private readonly signers;
|
|
911
|
-
constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
|
|
912
|
-
getAddress(): Promise<string>;
|
|
913
|
-
registerOffchain(): Promise<RegisterUserResponse>;
|
|
914
|
-
batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
|
|
915
|
-
cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
|
|
916
|
-
completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
|
|
917
|
-
createOrder(request: UnsignedOrderRequest): Promise<CreateOrderResponse>;
|
|
918
|
-
createTrade(request: GetSignableTradeRequest): Promise<CreateTradeResponse>;
|
|
919
|
-
deposit(tokenAmount: TokenAmount): Promise<TransactionResponse>;
|
|
920
|
-
exchangeTransfer(request: UnsignedExchangeTransferRequest): Promise<CreateTransferResponseV1>;
|
|
921
|
-
isRegisteredOnchain(): Promise<boolean>;
|
|
922
|
-
prepareWithdrawal(request: TokenAmount): Promise<CreateWithdrawalResponse>;
|
|
923
|
-
transfer(request: UnsignedTransferRequest): Promise<CreateTransferResponseV1>;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
declare class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
927
|
-
private static imxSigner;
|
|
928
|
-
static connect(config: ProviderConfiguration$1): Promise<MetaMaskIMXProvider>;
|
|
929
|
-
static disconnect(): Promise<void>;
|
|
930
|
-
static signMessage(message: string): Promise<string>;
|
|
931
|
-
}
|
|
932
|
-
|
|
933
912
|
declare enum Environment {
|
|
934
913
|
PRODUCTION = "production",
|
|
935
914
|
SANDBOX = "sandbox"
|
|
@@ -962,4 +941,30 @@ declare class ProviderConfiguration {
|
|
|
962
941
|
constructor({ baseConfig, overrides }: ProviderModuleConfiguration);
|
|
963
942
|
}
|
|
964
943
|
|
|
944
|
+
declare class GenericIMXProvider implements IMXProvider {
|
|
945
|
+
private readonly config;
|
|
946
|
+
private readonly signers;
|
|
947
|
+
constructor(config: ProviderConfiguration, ethSigner: Signer, starkSigner: StarkSigner);
|
|
948
|
+
getAddress(): Promise<string>;
|
|
949
|
+
isRegisteredOffchain(): Promise<boolean>;
|
|
950
|
+
registerOffchain(): Promise<RegisterUserResponse>;
|
|
951
|
+
batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
|
|
952
|
+
cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
|
|
953
|
+
completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
|
|
954
|
+
createOrder(request: UnsignedOrderRequest): Promise<CreateOrderResponse>;
|
|
955
|
+
createTrade(request: GetSignableTradeRequest): Promise<CreateTradeResponse>;
|
|
956
|
+
deposit(tokenAmount: TokenAmount): Promise<TransactionResponse>;
|
|
957
|
+
exchangeTransfer(request: UnsignedExchangeTransferRequest): Promise<CreateTransferResponseV1>;
|
|
958
|
+
isRegisteredOnchain(): Promise<boolean>;
|
|
959
|
+
prepareWithdrawal(request: TokenAmount): Promise<CreateWithdrawalResponse>;
|
|
960
|
+
transfer(request: UnsignedTransferRequest): Promise<CreateTransferResponseV1>;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
declare class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
964
|
+
private static imxSigner;
|
|
965
|
+
static connect(config: ProviderConfiguration): Promise<MetaMaskIMXProvider>;
|
|
966
|
+
static disconnect(): Promise<void>;
|
|
967
|
+
static signMessage(message: string): Promise<string>;
|
|
968
|
+
}
|
|
969
|
+
|
|
965
970
|
export { GenericIMXProvider, IMXProvider, MetaMaskIMXProvider, ProviderConfiguration };
|
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-alpha.2",
|
|
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": {
|
|
@@ -90,14 +90,6 @@
|
|
|
90
90
|
"./provider": {
|
|
91
91
|
"types": "./dist/provider.d.ts",
|
|
92
92
|
"import": "./dist/provider.js"
|
|
93
|
-
},
|
|
94
|
-
"./checkout_sdk": {
|
|
95
|
-
"types": "./dist/checkout_sdk.d.ts",
|
|
96
|
-
"import": "./dist/checkout_sdk.js"
|
|
97
|
-
},
|
|
98
|
-
"./checkout_widgets": {
|
|
99
|
-
"types": "./dist/checkout_widgets.d.ts",
|
|
100
|
-
"import": "./dist/checkout_widgets.js"
|
|
101
93
|
}
|
|
102
94
|
},
|
|
103
95
|
"files": [
|