@imtbl/sdk 0.30.1 → 0.30.3
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/sdk.js +1 -1
- package/dist/browser/checkout/widgets.js +56 -56
- package/dist/checkout_sdk.js +2 -2
- 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 +45 -39
- package/dist/index.js +45 -39
- package/dist/passport.js +43 -37
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var BN$2 = require('bn.js');
|
|
|
13
13
|
var encUtils = require('enc-utils');
|
|
14
14
|
var events = require('events');
|
|
15
15
|
var abi = require('@0xsequence/abi');
|
|
16
|
-
var
|
|
16
|
+
var core = require('@0xsequence/core');
|
|
17
17
|
var FormData$2 = require('form-data');
|
|
18
18
|
var seaportJs = require('@opensea/seaport-js');
|
|
19
19
|
var units = require('@ethersproject/units');
|
|
@@ -3792,7 +3792,7 @@ class MultiRollupApiClients {
|
|
|
3792
3792
|
}
|
|
3793
3793
|
|
|
3794
3794
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3795
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.
|
|
3795
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.3' };
|
|
3796
3796
|
const createConfig = ({ basePath, headers, }) => {
|
|
3797
3797
|
if (!basePath.trim()) {
|
|
3798
3798
|
throw Error('basePath can not be empty');
|
|
@@ -3852,7 +3852,7 @@ class APIError extends Error {
|
|
|
3852
3852
|
|
|
3853
3853
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3854
3854
|
const defaultHeaders = {
|
|
3855
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.
|
|
3855
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.3',
|
|
3856
3856
|
};
|
|
3857
3857
|
/**
|
|
3858
3858
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4263,7 +4263,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4263
4263
|
chainID,
|
|
4264
4264
|
coreContractAddress,
|
|
4265
4265
|
registrationContractAddress,
|
|
4266
|
-
sdkVersion: 'ts-immutable-sdk-0.30.
|
|
4266
|
+
sdkVersion: 'ts-immutable-sdk-0.30.3',
|
|
4267
4267
|
});
|
|
4268
4268
|
/**
|
|
4269
4269
|
* Sets `sdkVersion` at the time of build
|
|
@@ -8978,7 +8978,7 @@ class AuthManager {
|
|
|
8978
8978
|
nickname: idTokenPayload.nickname,
|
|
8979
8979
|
},
|
|
8980
8980
|
};
|
|
8981
|
-
if (idTokenPayload?.passport
|
|
8981
|
+
if (idTokenPayload?.passport?.imx_eth_address) {
|
|
8982
8982
|
user.imx = {
|
|
8983
8983
|
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
8984
8984
|
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
@@ -9033,10 +9033,7 @@ class AuthManager {
|
|
|
9033
9033
|
try {
|
|
9034
9034
|
const tokenResponse = await this.getDeviceFlowToken(deviceCode);
|
|
9035
9035
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
9036
|
-
|
|
9037
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
9038
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9039
|
-
}
|
|
9036
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9040
9037
|
return user;
|
|
9041
9038
|
}
|
|
9042
9039
|
catch (error) {
|
|
@@ -9108,10 +9105,7 @@ class AuthManager {
|
|
|
9108
9105
|
}
|
|
9109
9106
|
const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
|
|
9110
9107
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
9111
|
-
|
|
9112
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
9113
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9114
|
-
}
|
|
9108
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9115
9109
|
return user;
|
|
9116
9110
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
9117
9111
|
}
|
|
@@ -9165,21 +9159,11 @@ class AuthManager {
|
|
|
9165
9159
|
this.deviceCredentialsManager.clearCredentials();
|
|
9166
9160
|
}, PassportErrorType.LOGOUT_ERROR);
|
|
9167
9161
|
}
|
|
9168
|
-
async loginSilent({ forceRefresh } = { forceRefresh: false }) {
|
|
9169
|
-
// eslint-disable-next-line arrow-body-style
|
|
9170
|
-
return withPassportError(async () => {
|
|
9171
|
-
return this.getUser({ forceRefresh });
|
|
9172
|
-
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
9173
|
-
}
|
|
9174
9162
|
/**
|
|
9175
9163
|
* Get the user from the cache or refresh the token if it's expired.
|
|
9176
|
-
*
|
|
9177
|
-
* throw an error if there's no refresh token.
|
|
9164
|
+
* return null if there's no refresh token.
|
|
9178
9165
|
*/
|
|
9179
|
-
async getAuthenticatedUser(
|
|
9180
|
-
if (forceRefresh) {
|
|
9181
|
-
return this.refreshTokenAndUpdatePromise();
|
|
9182
|
-
}
|
|
9166
|
+
async getAuthenticatedUser() {
|
|
9183
9167
|
const oidcUser = await this.userManager.getUser();
|
|
9184
9168
|
if (!oidcUser)
|
|
9185
9169
|
return null;
|
|
@@ -9191,6 +9175,9 @@ class AuthManager {
|
|
|
9191
9175
|
}
|
|
9192
9176
|
return null;
|
|
9193
9177
|
}
|
|
9178
|
+
async forceUserRefresh() {
|
|
9179
|
+
return this.refreshTokenAndUpdatePromise();
|
|
9180
|
+
}
|
|
9194
9181
|
/**
|
|
9195
9182
|
* Refreshes the token and returns the user.
|
|
9196
9183
|
* If the token is already being refreshed, returns the existing promise.
|
|
@@ -9217,9 +9204,9 @@ class AuthManager {
|
|
|
9217
9204
|
});
|
|
9218
9205
|
return this.refreshingPromise;
|
|
9219
9206
|
}
|
|
9220
|
-
async getUser(
|
|
9207
|
+
async getUser() {
|
|
9221
9208
|
return withPassportError(async () => {
|
|
9222
|
-
const user = await this.getAuthenticatedUser(
|
|
9209
|
+
const user = await this.getAuthenticatedUser();
|
|
9223
9210
|
if (user)
|
|
9224
9211
|
return user;
|
|
9225
9212
|
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
@@ -9830,7 +9817,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
9830
9817
|
async function forceUserRefresh(authManager) {
|
|
9831
9818
|
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9832
9819
|
await retryWithDelay(async () => {
|
|
9833
|
-
const user = await authManager.
|
|
9820
|
+
const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
|
|
9834
9821
|
if (user?.imx)
|
|
9835
9822
|
return user;
|
|
9836
9823
|
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
@@ -10057,7 +10044,7 @@ class PassportImxProviderFactory {
|
|
|
10057
10044
|
async getProvider() {
|
|
10058
10045
|
let user = null;
|
|
10059
10046
|
try {
|
|
10060
|
-
user = await this.authManager.
|
|
10047
|
+
user = await this.authManager.getUser();
|
|
10061
10048
|
}
|
|
10062
10049
|
catch (e) {
|
|
10063
10050
|
// eslint-disable-next-line no-console
|
|
@@ -10069,7 +10056,7 @@ class PassportImxProviderFactory {
|
|
|
10069
10056
|
return this.createProviderInstance(user);
|
|
10070
10057
|
}
|
|
10071
10058
|
async getProviderSilent() {
|
|
10072
|
-
const user = await this.authManager.
|
|
10059
|
+
const user = await this.authManager.getUser();
|
|
10073
10060
|
if (!user) {
|
|
10074
10061
|
return null;
|
|
10075
10062
|
}
|
|
@@ -10452,10 +10439,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
10452
10439
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
10453
10440
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
10454
10441
|
// Add metadata
|
|
10455
|
-
const encodedSignature =
|
|
10442
|
+
const encodedSignature = core.v1.signature.encodeSignature({
|
|
10443
|
+
version: 1,
|
|
10456
10444
|
threshold: TRANSACTION_SIGNATURE_THRESHOLD,
|
|
10457
10445
|
signers: [
|
|
10458
10446
|
{
|
|
10447
|
+
isDynamic: false,
|
|
10448
|
+
unrecovered: true,
|
|
10459
10449
|
weight: SIGNATURE_WEIGHT,
|
|
10460
10450
|
signature: signedDigest,
|
|
10461
10451
|
},
|
|
@@ -10470,8 +10460,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
10470
10460
|
]);
|
|
10471
10461
|
};
|
|
10472
10462
|
const decodeRelayerTypedDataSignature = (relayerSignature) => {
|
|
10473
|
-
const signatureWithThreshold = `
|
|
10474
|
-
return
|
|
10463
|
+
const signatureWithThreshold = `0x0000${relayerSignature}`;
|
|
10464
|
+
return core.v1.signature.decodeSignature(signatureWithThreshold);
|
|
10475
10465
|
};
|
|
10476
10466
|
const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
|
|
10477
10467
|
// Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
|
|
@@ -10487,11 +10477,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
|
|
|
10487
10477
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
10488
10478
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
10489
10479
|
const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
|
|
10490
|
-
return
|
|
10480
|
+
return core.v1.signature.encodeSignature({
|
|
10481
|
+
version: 1,
|
|
10491
10482
|
threshold: EIP712_SIGNATURE_THRESHOLD,
|
|
10492
10483
|
signers: [
|
|
10493
10484
|
...signers,
|
|
10494
10485
|
{
|
|
10486
|
+
isDynamic: false,
|
|
10487
|
+
unrecovered: true,
|
|
10495
10488
|
weight: SIGNATURE_WEIGHT,
|
|
10496
10489
|
signature: signedDigest,
|
|
10497
10490
|
},
|
|
@@ -10634,7 +10627,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
10634
10627
|
user = await authManager.refreshToken(credentials.refresh_token);
|
|
10635
10628
|
}
|
|
10636
10629
|
else {
|
|
10637
|
-
user = await authManager.
|
|
10630
|
+
user = await authManager.forceUserRefresh();
|
|
10638
10631
|
}
|
|
10639
10632
|
if (!user?.zkEvm) {
|
|
10640
10633
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
@@ -10643,7 +10636,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
10643
10636
|
}
|
|
10644
10637
|
|
|
10645
10638
|
const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
10646
|
-
|
|
10639
|
+
let user = null;
|
|
10640
|
+
try {
|
|
10641
|
+
user = await authManager.getUser();
|
|
10642
|
+
}
|
|
10643
|
+
catch (err) {
|
|
10644
|
+
// eslint-disable-next-line no-console
|
|
10645
|
+
console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
|
|
10646
|
+
}
|
|
10647
|
+
if (!user) {
|
|
10648
|
+
user = await authManager.getUserDeviceFlow() || await authManager.login();
|
|
10649
|
+
}
|
|
10647
10650
|
if (!user.idToken) {
|
|
10648
10651
|
throw new Error('User is missing idToken');
|
|
10649
10652
|
}
|
|
@@ -11119,11 +11122,14 @@ class Passport {
|
|
|
11119
11122
|
const { useCachedSession = false } = options || {};
|
|
11120
11123
|
let user = null;
|
|
11121
11124
|
try {
|
|
11122
|
-
user = await this.authManager.
|
|
11125
|
+
user = await this.authManager.getUser();
|
|
11123
11126
|
}
|
|
11124
11127
|
catch (error) {
|
|
11128
|
+
if (useCachedSession) {
|
|
11129
|
+
throw error;
|
|
11130
|
+
}
|
|
11125
11131
|
// eslint-disable-next-line no-console
|
|
11126
|
-
console.warn('
|
|
11132
|
+
console.warn('login failed to retrieve a cached user session', error);
|
|
11127
11133
|
}
|
|
11128
11134
|
if (!user && !useCachedSession) {
|
|
11129
11135
|
user = await this.authManager.login();
|
|
@@ -34018,7 +34024,7 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
|
|
|
34018
34024
|
return itemRequirements;
|
|
34019
34025
|
}
|
|
34020
34026
|
|
|
34021
|
-
const SDK_VERSION_MARKER = '0.30.
|
|
34027
|
+
const SDK_VERSION_MARKER = '0.30.3';
|
|
34022
34028
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
34023
34029
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
34024
34030
|
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import BN$2 from 'bn.js';
|
|
|
11
11
|
import * as encUtils from 'enc-utils';
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
13
|
import { walletContracts } from '@0xsequence/abi';
|
|
14
|
-
import {
|
|
14
|
+
import { v1 } from '@0xsequence/core';
|
|
15
15
|
import FormData$2 from 'form-data';
|
|
16
16
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
17
17
|
import { parseUnits } from '@ethersproject/units';
|
|
@@ -3770,7 +3770,7 @@ class MultiRollupApiClients {
|
|
|
3770
3770
|
}
|
|
3771
3771
|
|
|
3772
3772
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3773
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.
|
|
3773
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.3' };
|
|
3774
3774
|
const createConfig = ({ basePath, headers, }) => {
|
|
3775
3775
|
if (!basePath.trim()) {
|
|
3776
3776
|
throw Error('basePath can not be empty');
|
|
@@ -3830,7 +3830,7 @@ class APIError extends Error {
|
|
|
3830
3830
|
|
|
3831
3831
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3832
3832
|
const defaultHeaders = {
|
|
3833
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.
|
|
3833
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.3',
|
|
3834
3834
|
};
|
|
3835
3835
|
/**
|
|
3836
3836
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4241,7 +4241,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4241
4241
|
chainID,
|
|
4242
4242
|
coreContractAddress,
|
|
4243
4243
|
registrationContractAddress,
|
|
4244
|
-
sdkVersion: 'ts-immutable-sdk-0.30.
|
|
4244
|
+
sdkVersion: 'ts-immutable-sdk-0.30.3',
|
|
4245
4245
|
});
|
|
4246
4246
|
/**
|
|
4247
4247
|
* Sets `sdkVersion` at the time of build
|
|
@@ -8956,7 +8956,7 @@ class AuthManager {
|
|
|
8956
8956
|
nickname: idTokenPayload.nickname,
|
|
8957
8957
|
},
|
|
8958
8958
|
};
|
|
8959
|
-
if (idTokenPayload?.passport
|
|
8959
|
+
if (idTokenPayload?.passport?.imx_eth_address) {
|
|
8960
8960
|
user.imx = {
|
|
8961
8961
|
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
8962
8962
|
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
@@ -9011,10 +9011,7 @@ class AuthManager {
|
|
|
9011
9011
|
try {
|
|
9012
9012
|
const tokenResponse = await this.getDeviceFlowToken(deviceCode);
|
|
9013
9013
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
9014
|
-
|
|
9015
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
9016
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9017
|
-
}
|
|
9014
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9018
9015
|
return user;
|
|
9019
9016
|
}
|
|
9020
9017
|
catch (error) {
|
|
@@ -9086,10 +9083,7 @@ class AuthManager {
|
|
|
9086
9083
|
}
|
|
9087
9084
|
const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
|
|
9088
9085
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
9089
|
-
|
|
9090
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
9091
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9092
|
-
}
|
|
9086
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
9093
9087
|
return user;
|
|
9094
9088
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
9095
9089
|
}
|
|
@@ -9143,21 +9137,11 @@ class AuthManager {
|
|
|
9143
9137
|
this.deviceCredentialsManager.clearCredentials();
|
|
9144
9138
|
}, PassportErrorType.LOGOUT_ERROR);
|
|
9145
9139
|
}
|
|
9146
|
-
async loginSilent({ forceRefresh } = { forceRefresh: false }) {
|
|
9147
|
-
// eslint-disable-next-line arrow-body-style
|
|
9148
|
-
return withPassportError(async () => {
|
|
9149
|
-
return this.getUser({ forceRefresh });
|
|
9150
|
-
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
9151
|
-
}
|
|
9152
9140
|
/**
|
|
9153
9141
|
* Get the user from the cache or refresh the token if it's expired.
|
|
9154
|
-
*
|
|
9155
|
-
* throw an error if there's no refresh token.
|
|
9142
|
+
* return null if there's no refresh token.
|
|
9156
9143
|
*/
|
|
9157
|
-
async getAuthenticatedUser(
|
|
9158
|
-
if (forceRefresh) {
|
|
9159
|
-
return this.refreshTokenAndUpdatePromise();
|
|
9160
|
-
}
|
|
9144
|
+
async getAuthenticatedUser() {
|
|
9161
9145
|
const oidcUser = await this.userManager.getUser();
|
|
9162
9146
|
if (!oidcUser)
|
|
9163
9147
|
return null;
|
|
@@ -9169,6 +9153,9 @@ class AuthManager {
|
|
|
9169
9153
|
}
|
|
9170
9154
|
return null;
|
|
9171
9155
|
}
|
|
9156
|
+
async forceUserRefresh() {
|
|
9157
|
+
return this.refreshTokenAndUpdatePromise();
|
|
9158
|
+
}
|
|
9172
9159
|
/**
|
|
9173
9160
|
* Refreshes the token and returns the user.
|
|
9174
9161
|
* If the token is already being refreshed, returns the existing promise.
|
|
@@ -9195,9 +9182,9 @@ class AuthManager {
|
|
|
9195
9182
|
});
|
|
9196
9183
|
return this.refreshingPromise;
|
|
9197
9184
|
}
|
|
9198
|
-
async getUser(
|
|
9185
|
+
async getUser() {
|
|
9199
9186
|
return withPassportError(async () => {
|
|
9200
|
-
const user = await this.getAuthenticatedUser(
|
|
9187
|
+
const user = await this.getAuthenticatedUser();
|
|
9201
9188
|
if (user)
|
|
9202
9189
|
return user;
|
|
9203
9190
|
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
@@ -9808,7 +9795,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
9808
9795
|
async function forceUserRefresh(authManager) {
|
|
9809
9796
|
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9810
9797
|
await retryWithDelay(async () => {
|
|
9811
|
-
const user = await authManager.
|
|
9798
|
+
const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
|
|
9812
9799
|
if (user?.imx)
|
|
9813
9800
|
return user;
|
|
9814
9801
|
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
@@ -10035,7 +10022,7 @@ class PassportImxProviderFactory {
|
|
|
10035
10022
|
async getProvider() {
|
|
10036
10023
|
let user = null;
|
|
10037
10024
|
try {
|
|
10038
|
-
user = await this.authManager.
|
|
10025
|
+
user = await this.authManager.getUser();
|
|
10039
10026
|
}
|
|
10040
10027
|
catch (e) {
|
|
10041
10028
|
// eslint-disable-next-line no-console
|
|
@@ -10047,7 +10034,7 @@ class PassportImxProviderFactory {
|
|
|
10047
10034
|
return this.createProviderInstance(user);
|
|
10048
10035
|
}
|
|
10049
10036
|
async getProviderSilent() {
|
|
10050
|
-
const user = await this.authManager.
|
|
10037
|
+
const user = await this.authManager.getUser();
|
|
10051
10038
|
if (!user) {
|
|
10052
10039
|
return null;
|
|
10053
10040
|
}
|
|
@@ -10430,10 +10417,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
10430
10417
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
10431
10418
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
10432
10419
|
// Add metadata
|
|
10433
|
-
const encodedSignature = encodeSignature({
|
|
10420
|
+
const encodedSignature = v1.signature.encodeSignature({
|
|
10421
|
+
version: 1,
|
|
10434
10422
|
threshold: TRANSACTION_SIGNATURE_THRESHOLD,
|
|
10435
10423
|
signers: [
|
|
10436
10424
|
{
|
|
10425
|
+
isDynamic: false,
|
|
10426
|
+
unrecovered: true,
|
|
10437
10427
|
weight: SIGNATURE_WEIGHT,
|
|
10438
10428
|
signature: signedDigest,
|
|
10439
10429
|
},
|
|
@@ -10448,8 +10438,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
10448
10438
|
]);
|
|
10449
10439
|
};
|
|
10450
10440
|
const decodeRelayerTypedDataSignature = (relayerSignature) => {
|
|
10451
|
-
const signatureWithThreshold = `
|
|
10452
|
-
return decodeSignature(signatureWithThreshold);
|
|
10441
|
+
const signatureWithThreshold = `0x0000${relayerSignature}`;
|
|
10442
|
+
return v1.signature.decodeSignature(signatureWithThreshold);
|
|
10453
10443
|
};
|
|
10454
10444
|
const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
|
|
10455
10445
|
// Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
|
|
@@ -10465,11 +10455,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
|
|
|
10465
10455
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
10466
10456
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
10467
10457
|
const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
|
|
10468
|
-
return encodeSignature({
|
|
10458
|
+
return v1.signature.encodeSignature({
|
|
10459
|
+
version: 1,
|
|
10469
10460
|
threshold: EIP712_SIGNATURE_THRESHOLD,
|
|
10470
10461
|
signers: [
|
|
10471
10462
|
...signers,
|
|
10472
10463
|
{
|
|
10464
|
+
isDynamic: false,
|
|
10465
|
+
unrecovered: true,
|
|
10473
10466
|
weight: SIGNATURE_WEIGHT,
|
|
10474
10467
|
signature: signedDigest,
|
|
10475
10468
|
},
|
|
@@ -10612,7 +10605,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
10612
10605
|
user = await authManager.refreshToken(credentials.refresh_token);
|
|
10613
10606
|
}
|
|
10614
10607
|
else {
|
|
10615
|
-
user = await authManager.
|
|
10608
|
+
user = await authManager.forceUserRefresh();
|
|
10616
10609
|
}
|
|
10617
10610
|
if (!user?.zkEvm) {
|
|
10618
10611
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
@@ -10621,7 +10614,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
10621
10614
|
}
|
|
10622
10615
|
|
|
10623
10616
|
const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
10624
|
-
|
|
10617
|
+
let user = null;
|
|
10618
|
+
try {
|
|
10619
|
+
user = await authManager.getUser();
|
|
10620
|
+
}
|
|
10621
|
+
catch (err) {
|
|
10622
|
+
// eslint-disable-next-line no-console
|
|
10623
|
+
console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
|
|
10624
|
+
}
|
|
10625
|
+
if (!user) {
|
|
10626
|
+
user = await authManager.getUserDeviceFlow() || await authManager.login();
|
|
10627
|
+
}
|
|
10625
10628
|
if (!user.idToken) {
|
|
10626
10629
|
throw new Error('User is missing idToken');
|
|
10627
10630
|
}
|
|
@@ -11097,11 +11100,14 @@ class Passport {
|
|
|
11097
11100
|
const { useCachedSession = false } = options || {};
|
|
11098
11101
|
let user = null;
|
|
11099
11102
|
try {
|
|
11100
|
-
user = await this.authManager.
|
|
11103
|
+
user = await this.authManager.getUser();
|
|
11101
11104
|
}
|
|
11102
11105
|
catch (error) {
|
|
11106
|
+
if (useCachedSession) {
|
|
11107
|
+
throw error;
|
|
11108
|
+
}
|
|
11103
11109
|
// eslint-disable-next-line no-console
|
|
11104
|
-
console.warn('
|
|
11110
|
+
console.warn('login failed to retrieve a cached user session', error);
|
|
11105
11111
|
}
|
|
11106
11112
|
if (!user && !useCachedSession) {
|
|
11107
11113
|
user = await this.authManager.login();
|
|
@@ -33996,7 +34002,7 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
|
|
|
33996
34002
|
return itemRequirements;
|
|
33997
34003
|
}
|
|
33998
34004
|
|
|
33999
|
-
const SDK_VERSION_MARKER = '0.30.
|
|
34005
|
+
const SDK_VERSION_MARKER = '0.30.3';
|
|
34000
34006
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
34001
34007
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
34002
34008
|
|
package/dist/passport.js
CHANGED
|
@@ -11,7 +11,7 @@ import BN from 'bn.js';
|
|
|
11
11
|
import * as encUtils from 'enc-utils';
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
13
|
import { walletContracts } from '@0xsequence/abi';
|
|
14
|
-
import {
|
|
14
|
+
import { v1 } from '@0xsequence/core';
|
|
15
15
|
|
|
16
16
|
/* tslint:disable */
|
|
17
17
|
/* eslint-disable */
|
|
@@ -2191,7 +2191,7 @@ class MultiRollupApiClients {
|
|
|
2191
2191
|
}
|
|
2192
2192
|
|
|
2193
2193
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2194
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.30.
|
|
2194
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.30.3' };
|
|
2195
2195
|
const createConfig = ({ basePath, headers, }) => {
|
|
2196
2196
|
if (!basePath.trim()) {
|
|
2197
2197
|
throw Error('basePath can not be empty');
|
|
@@ -2247,7 +2247,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2247
2247
|
chainID,
|
|
2248
2248
|
coreContractAddress,
|
|
2249
2249
|
registrationContractAddress,
|
|
2250
|
-
sdkVersion: 'ts-immutable-sdk-0.30.
|
|
2250
|
+
sdkVersion: 'ts-immutable-sdk-0.30.3',
|
|
2251
2251
|
});
|
|
2252
2252
|
/**
|
|
2253
2253
|
* Sets `sdkVersion` at the time of build
|
|
@@ -6945,7 +6945,7 @@ class AuthManager {
|
|
|
6945
6945
|
nickname: idTokenPayload.nickname,
|
|
6946
6946
|
},
|
|
6947
6947
|
};
|
|
6948
|
-
if (idTokenPayload?.passport
|
|
6948
|
+
if (idTokenPayload?.passport?.imx_eth_address) {
|
|
6949
6949
|
user.imx = {
|
|
6950
6950
|
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
6951
6951
|
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
@@ -7000,10 +7000,7 @@ class AuthManager {
|
|
|
7000
7000
|
try {
|
|
7001
7001
|
const tokenResponse = await this.getDeviceFlowToken(deviceCode);
|
|
7002
7002
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
7003
|
-
|
|
7004
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
7005
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
7006
|
-
}
|
|
7003
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
7007
7004
|
return user;
|
|
7008
7005
|
}
|
|
7009
7006
|
catch (error) {
|
|
@@ -7075,10 +7072,7 @@ class AuthManager {
|
|
|
7075
7072
|
}
|
|
7076
7073
|
const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
|
|
7077
7074
|
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
7078
|
-
|
|
7079
|
-
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
7080
|
-
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
7081
|
-
}
|
|
7075
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
7082
7076
|
return user;
|
|
7083
7077
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
7084
7078
|
}
|
|
@@ -7132,21 +7126,11 @@ class AuthManager {
|
|
|
7132
7126
|
this.deviceCredentialsManager.clearCredentials();
|
|
7133
7127
|
}, PassportErrorType.LOGOUT_ERROR);
|
|
7134
7128
|
}
|
|
7135
|
-
async loginSilent({ forceRefresh } = { forceRefresh: false }) {
|
|
7136
|
-
// eslint-disable-next-line arrow-body-style
|
|
7137
|
-
return withPassportError(async () => {
|
|
7138
|
-
return this.getUser({ forceRefresh });
|
|
7139
|
-
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
7140
|
-
}
|
|
7141
7129
|
/**
|
|
7142
7130
|
* Get the user from the cache or refresh the token if it's expired.
|
|
7143
|
-
*
|
|
7144
|
-
* throw an error if there's no refresh token.
|
|
7131
|
+
* return null if there's no refresh token.
|
|
7145
7132
|
*/
|
|
7146
|
-
async getAuthenticatedUser(
|
|
7147
|
-
if (forceRefresh) {
|
|
7148
|
-
return this.refreshTokenAndUpdatePromise();
|
|
7149
|
-
}
|
|
7133
|
+
async getAuthenticatedUser() {
|
|
7150
7134
|
const oidcUser = await this.userManager.getUser();
|
|
7151
7135
|
if (!oidcUser)
|
|
7152
7136
|
return null;
|
|
@@ -7158,6 +7142,9 @@ class AuthManager {
|
|
|
7158
7142
|
}
|
|
7159
7143
|
return null;
|
|
7160
7144
|
}
|
|
7145
|
+
async forceUserRefresh() {
|
|
7146
|
+
return this.refreshTokenAndUpdatePromise();
|
|
7147
|
+
}
|
|
7161
7148
|
/**
|
|
7162
7149
|
* Refreshes the token and returns the user.
|
|
7163
7150
|
* If the token is already being refreshed, returns the existing promise.
|
|
@@ -7184,9 +7171,9 @@ class AuthManager {
|
|
|
7184
7171
|
});
|
|
7185
7172
|
return this.refreshingPromise;
|
|
7186
7173
|
}
|
|
7187
|
-
async getUser(
|
|
7174
|
+
async getUser() {
|
|
7188
7175
|
return withPassportError(async () => {
|
|
7189
|
-
const user = await this.getAuthenticatedUser(
|
|
7176
|
+
const user = await this.getAuthenticatedUser();
|
|
7190
7177
|
if (user)
|
|
7191
7178
|
return user;
|
|
7192
7179
|
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
@@ -7797,7 +7784,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
7797
7784
|
async function forceUserRefresh(authManager) {
|
|
7798
7785
|
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
7799
7786
|
await retryWithDelay(async () => {
|
|
7800
|
-
const user = await authManager.
|
|
7787
|
+
const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
|
|
7801
7788
|
if (user?.imx)
|
|
7802
7789
|
return user;
|
|
7803
7790
|
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
@@ -8024,7 +8011,7 @@ class PassportImxProviderFactory {
|
|
|
8024
8011
|
async getProvider() {
|
|
8025
8012
|
let user = null;
|
|
8026
8013
|
try {
|
|
8027
|
-
user = await this.authManager.
|
|
8014
|
+
user = await this.authManager.getUser();
|
|
8028
8015
|
}
|
|
8029
8016
|
catch (e) {
|
|
8030
8017
|
// eslint-disable-next-line no-console
|
|
@@ -8036,7 +8023,7 @@ class PassportImxProviderFactory {
|
|
|
8036
8023
|
return this.createProviderInstance(user);
|
|
8037
8024
|
}
|
|
8038
8025
|
async getProviderSilent() {
|
|
8039
|
-
const user = await this.authManager.
|
|
8026
|
+
const user = await this.authManager.getUser();
|
|
8040
8027
|
if (!user) {
|
|
8041
8028
|
return null;
|
|
8042
8029
|
}
|
|
@@ -8419,10 +8406,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
8419
8406
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
8420
8407
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
8421
8408
|
// Add metadata
|
|
8422
|
-
const encodedSignature = encodeSignature({
|
|
8409
|
+
const encodedSignature = v1.signature.encodeSignature({
|
|
8410
|
+
version: 1,
|
|
8423
8411
|
threshold: TRANSACTION_SIGNATURE_THRESHOLD,
|
|
8424
8412
|
signers: [
|
|
8425
8413
|
{
|
|
8414
|
+
isDynamic: false,
|
|
8415
|
+
unrecovered: true,
|
|
8426
8416
|
weight: SIGNATURE_WEIGHT,
|
|
8427
8417
|
signature: signedDigest,
|
|
8428
8418
|
},
|
|
@@ -8437,8 +8427,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
8437
8427
|
]);
|
|
8438
8428
|
};
|
|
8439
8429
|
const decodeRelayerTypedDataSignature = (relayerSignature) => {
|
|
8440
|
-
const signatureWithThreshold = `
|
|
8441
|
-
return decodeSignature(signatureWithThreshold);
|
|
8430
|
+
const signatureWithThreshold = `0x0000${relayerSignature}`;
|
|
8431
|
+
return v1.signature.decodeSignature(signatureWithThreshold);
|
|
8442
8432
|
};
|
|
8443
8433
|
const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
|
|
8444
8434
|
// Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
|
|
@@ -8454,11 +8444,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
|
|
|
8454
8444
|
const ethsigNoType = await signer.signMessage(hashArray);
|
|
8455
8445
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
8456
8446
|
const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
|
|
8457
|
-
return encodeSignature({
|
|
8447
|
+
return v1.signature.encodeSignature({
|
|
8448
|
+
version: 1,
|
|
8458
8449
|
threshold: EIP712_SIGNATURE_THRESHOLD,
|
|
8459
8450
|
signers: [
|
|
8460
8451
|
...signers,
|
|
8461
8452
|
{
|
|
8453
|
+
isDynamic: false,
|
|
8454
|
+
unrecovered: true,
|
|
8462
8455
|
weight: SIGNATURE_WEIGHT,
|
|
8463
8456
|
signature: signedDigest,
|
|
8464
8457
|
},
|
|
@@ -8601,7 +8594,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
8601
8594
|
user = await authManager.refreshToken(credentials.refresh_token);
|
|
8602
8595
|
}
|
|
8603
8596
|
else {
|
|
8604
|
-
user = await authManager.
|
|
8597
|
+
user = await authManager.forceUserRefresh();
|
|
8605
8598
|
}
|
|
8606
8599
|
if (!user?.zkEvm) {
|
|
8607
8600
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
@@ -8610,7 +8603,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
8610
8603
|
}
|
|
8611
8604
|
|
|
8612
8605
|
const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
8613
|
-
|
|
8606
|
+
let user = null;
|
|
8607
|
+
try {
|
|
8608
|
+
user = await authManager.getUser();
|
|
8609
|
+
}
|
|
8610
|
+
catch (err) {
|
|
8611
|
+
// eslint-disable-next-line no-console
|
|
8612
|
+
console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
|
|
8613
|
+
}
|
|
8614
|
+
if (!user) {
|
|
8615
|
+
user = await authManager.getUserDeviceFlow() || await authManager.login();
|
|
8616
|
+
}
|
|
8614
8617
|
if (!user.idToken) {
|
|
8615
8618
|
throw new Error('User is missing idToken');
|
|
8616
8619
|
}
|
|
@@ -9086,11 +9089,14 @@ class Passport {
|
|
|
9086
9089
|
const { useCachedSession = false } = options || {};
|
|
9087
9090
|
let user = null;
|
|
9088
9091
|
try {
|
|
9089
|
-
user = await this.authManager.
|
|
9092
|
+
user = await this.authManager.getUser();
|
|
9090
9093
|
}
|
|
9091
9094
|
catch (error) {
|
|
9095
|
+
if (useCachedSession) {
|
|
9096
|
+
throw error;
|
|
9097
|
+
}
|
|
9092
9098
|
// eslint-disable-next-line no-console
|
|
9093
|
-
console.warn('
|
|
9099
|
+
console.warn('login failed to retrieve a cached user session', error);
|
|
9094
9100
|
}
|
|
9095
9101
|
if (!user && !useCachedSession) {
|
|
9096
9102
|
user = await this.authManager.login();
|