@0xsequence/auth
Advanced tools
Comparing version 0.0.0-20241114193556 to 0.0.0-20241216114019
@@ -33,2 +33,3 @@ 'use strict'; | ||
this.indexerClients = new Map(); | ||
this.indexerGateway = void 0; | ||
this.projectAccessKey = void 0; | ||
@@ -60,3 +61,3 @@ this.projectAccessKey = projectAccessKey; | ||
} | ||
auth(maxTries = 5) { | ||
auth(maxTries = 5, referenceChainId) { | ||
var _this = this; | ||
@@ -70,3 +71,3 @@ if (this._initialAuthRequest) return this._initialAuthRequest; | ||
try { | ||
jwtAuth = (await _this.getJWT(true)).token; | ||
jwtAuth = (await _this.getJWT(true, referenceChainId)).token; | ||
break; | ||
@@ -84,3 +85,3 @@ } catch (error) { | ||
} | ||
async getJWT(tryAuth) { | ||
async getJWT(tryAuth, referenceChainId) { | ||
var _this2 = this; | ||
@@ -114,7 +115,16 @@ const url = this.settings.sequenceApiUrl; | ||
token: proofString.then(async function (proofString) { | ||
var _authResp; | ||
const api$1 = new api.SequenceAPIClient(url); | ||
const authResp = await api$1.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
if ((authResp == null ? void 0 : authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
let authResp; | ||
if (referenceChainId) { | ||
authResp = await api$1.getAuthToken2({ | ||
ewtString: proofString, | ||
chainID: referenceChainId == null ? void 0 : referenceChainId.toString() | ||
}); | ||
} else { | ||
authResp = await api$1.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
} | ||
if (((_authResp = authResp) == null ? void 0 : _authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
return authResp.jwtToken; | ||
@@ -218,2 +228,9 @@ } else { | ||
} | ||
async getIndexerGateway(tryAuth = true) { | ||
if (!this.indexerGateway) { | ||
const jwtAuth = (await this.getJWT(tryAuth)).token; | ||
this.indexerGateway = new indexer.SequenceIndexerGateway(this.settings.sequenceMetadataUrl, undefined, jwtAuth); | ||
} | ||
return this.indexerGateway; | ||
} | ||
getProofString(key) { | ||
@@ -318,9 +335,14 @@ // check if we already have or are waiting for a proof string | ||
function _extends() { | ||
return _extends = Object.assign ? Object.assign.bind() : function (n) { | ||
for (var e = 1; e < arguments.length; e++) { | ||
var t = arguments[e]; | ||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return n; | ||
}, _extends.apply(null, arguments); | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
@@ -550,3 +572,3 @@ | ||
// otherwise the tracker will not know about this account | ||
await account$1.publishWitness(); | ||
await account$1.publishWitness(undefined, referenceChainId); | ||
@@ -566,3 +588,3 @@ // safety check, the remove tracker should be able to find | ||
servicesObj = new Services(account$1, services); | ||
servicesObj.auth(); // fire and forget | ||
servicesObj.auth(undefined, referenceChainId); // fire and forget | ||
@@ -569,0 +591,0 @@ servicesObj.onAuth(result => { |
@@ -33,2 +33,3 @@ 'use strict'; | ||
this.indexerClients = new Map(); | ||
this.indexerGateway = void 0; | ||
this.projectAccessKey = void 0; | ||
@@ -60,3 +61,3 @@ this.projectAccessKey = projectAccessKey; | ||
} | ||
auth(maxTries = 5) { | ||
auth(maxTries = 5, referenceChainId) { | ||
var _this = this; | ||
@@ -70,3 +71,3 @@ if (this._initialAuthRequest) return this._initialAuthRequest; | ||
try { | ||
jwtAuth = (await _this.getJWT(true)).token; | ||
jwtAuth = (await _this.getJWT(true, referenceChainId)).token; | ||
break; | ||
@@ -84,3 +85,3 @@ } catch (error) { | ||
} | ||
async getJWT(tryAuth) { | ||
async getJWT(tryAuth, referenceChainId) { | ||
var _this2 = this; | ||
@@ -114,7 +115,16 @@ const url = this.settings.sequenceApiUrl; | ||
token: proofString.then(async function (proofString) { | ||
var _authResp; | ||
const api$1 = new api.SequenceAPIClient(url); | ||
const authResp = await api$1.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
if ((authResp == null ? void 0 : authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
let authResp; | ||
if (referenceChainId) { | ||
authResp = await api$1.getAuthToken2({ | ||
ewtString: proofString, | ||
chainID: referenceChainId == null ? void 0 : referenceChainId.toString() | ||
}); | ||
} else { | ||
authResp = await api$1.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
} | ||
if (((_authResp = authResp) == null ? void 0 : _authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
return authResp.jwtToken; | ||
@@ -218,2 +228,9 @@ } else { | ||
} | ||
async getIndexerGateway(tryAuth = true) { | ||
if (!this.indexerGateway) { | ||
const jwtAuth = (await this.getJWT(tryAuth)).token; | ||
this.indexerGateway = new indexer.SequenceIndexerGateway(this.settings.sequenceMetadataUrl, undefined, jwtAuth); | ||
} | ||
return this.indexerGateway; | ||
} | ||
getProofString(key) { | ||
@@ -318,9 +335,14 @@ // check if we already have or are waiting for a proof string | ||
function _extends() { | ||
return _extends = Object.assign ? Object.assign.bind() : function (n) { | ||
for (var e = 1; e < arguments.length; e++) { | ||
var t = arguments[e]; | ||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return n; | ||
}, _extends.apply(null, arguments); | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
@@ -550,3 +572,3 @@ | ||
// otherwise the tracker will not know about this account | ||
await account$1.publishWitness(); | ||
await account$1.publishWitness(undefined, referenceChainId); | ||
@@ -566,3 +588,3 @@ // safety check, the remove tracker should be able to find | ||
servicesObj = new Services(account$1, services); | ||
servicesObj.auth(); // fire and forget | ||
servicesObj.auth(undefined, referenceChainId); // fire and forget | ||
@@ -569,0 +591,0 @@ servicesObj.onAuth(result => { |
@@ -6,3 +6,3 @@ import { ethers } from 'ethers'; | ||
import { SequenceAPIClient } from '@0xsequence/api'; | ||
import { SequenceIndexer } from '@0xsequence/indexer'; | ||
import { SequenceIndexer, SequenceIndexerGateway } from '@0xsequence/indexer'; | ||
import { SequenceMetadata } from '@0xsequence/metadata'; | ||
@@ -30,2 +30,3 @@ import { getFetchRequest, jwtDecodeClaims } from '@0xsequence/utils'; | ||
this.indexerClients = new Map(); | ||
this.indexerGateway = void 0; | ||
this.projectAccessKey = void 0; | ||
@@ -57,3 +58,3 @@ this.projectAccessKey = projectAccessKey; | ||
} | ||
auth(maxTries = 5) { | ||
auth(maxTries = 5, referenceChainId) { | ||
var _this = this; | ||
@@ -67,3 +68,3 @@ if (this._initialAuthRequest) return this._initialAuthRequest; | ||
try { | ||
jwtAuth = (await _this.getJWT(true)).token; | ||
jwtAuth = (await _this.getJWT(true, referenceChainId)).token; | ||
break; | ||
@@ -81,3 +82,3 @@ } catch (error) { | ||
} | ||
async getJWT(tryAuth) { | ||
async getJWT(tryAuth, referenceChainId) { | ||
var _this2 = this; | ||
@@ -111,7 +112,16 @@ const url = this.settings.sequenceApiUrl; | ||
token: proofString.then(async function (proofString) { | ||
var _authResp; | ||
const api = new SequenceAPIClient(url); | ||
const authResp = await api.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
if ((authResp == null ? void 0 : authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
let authResp; | ||
if (referenceChainId) { | ||
authResp = await api.getAuthToken2({ | ||
ewtString: proofString, | ||
chainID: referenceChainId == null ? void 0 : referenceChainId.toString() | ||
}); | ||
} else { | ||
authResp = await api.getAuthToken({ | ||
ewtString: proofString | ||
}); | ||
} | ||
if (((_authResp = authResp) == null ? void 0 : _authResp.status) === true && authResp.jwtToken.length !== 0) { | ||
return authResp.jwtToken; | ||
@@ -215,2 +225,9 @@ } else { | ||
} | ||
async getIndexerGateway(tryAuth = true) { | ||
if (!this.indexerGateway) { | ||
const jwtAuth = (await this.getJWT(tryAuth)).token; | ||
this.indexerGateway = new SequenceIndexerGateway(this.settings.sequenceMetadataUrl, undefined, jwtAuth); | ||
} | ||
return this.indexerGateway; | ||
} | ||
getProofString(key) { | ||
@@ -315,9 +332,14 @@ // check if we already have or are waiting for a proof string | ||
function _extends() { | ||
return _extends = Object.assign ? Object.assign.bind() : function (n) { | ||
for (var e = 1; e < arguments.length; e++) { | ||
var t = arguments[e]; | ||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return n; | ||
}, _extends.apply(null, arguments); | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
@@ -547,3 +569,3 @@ | ||
// otherwise the tracker will not know about this account | ||
await account.publishWitness(); | ||
await account.publishWitness(undefined, referenceChainId); | ||
@@ -563,3 +585,3 @@ // safety check, the remove tracker should be able to find | ||
servicesObj = new Services(account, services); | ||
servicesObj.auth(); // fire and forget | ||
servicesObj.auth(undefined, referenceChainId); // fire and forget | ||
@@ -566,0 +588,0 @@ servicesObj.onAuth(result => { |
import { Account } from '@0xsequence/account'; | ||
import { SequenceAPIClient } from '@0xsequence/api'; | ||
import { Indexer } from '@0xsequence/indexer'; | ||
import { Indexer, SequenceIndexerGateway } from '@0xsequence/indexer'; | ||
import { SequenceMetadata } from '@0xsequence/metadata'; | ||
@@ -16,2 +16,3 @@ import { ChainIdLike } from '@0xsequence/network'; | ||
sequenceMetadataUrl: string; | ||
sequenceIndexerGatewayUrl: string; | ||
}; | ||
@@ -45,2 +46,3 @@ export type SessionJWT = { | ||
private indexerClients; | ||
private indexerGateway; | ||
private projectAccessKey?; | ||
@@ -58,3 +60,3 @@ constructor(account: Account, settings: ServicesSettings, status?: { | ||
}>; | ||
auth(maxTries?: number): Promise<SequenceAPIClient>; | ||
auth(maxTries?: number, referenceChainId?: ChainIdLike): Promise<SequenceAPIClient>; | ||
private getJWT; | ||
@@ -66,3 +68,4 @@ private getProofStringKey; | ||
getIndexerClient(chainId: ChainIdLike, tryAuth?: boolean): Promise<Indexer>; | ||
getIndexerGateway(tryAuth?: boolean): Promise<SequenceIndexerGateway>; | ||
private getProofString; | ||
} |
{ | ||
"name": "@0xsequence/auth", | ||
"version": "0.0.0-20241114193556", | ||
"version": "0.0.0-20241216114019", | ||
"description": "auth sub-package for Sequence", | ||
@@ -13,14 +13,14 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/auth", | ||
"@0xsequence/ethauth": "^1.0.0", | ||
"@0xsequence/abi": "0.0.0-20241114193556", | ||
"@0xsequence/account": "0.0.0-20241114193556", | ||
"@0xsequence/api": "0.0.0-20241114193556", | ||
"@0xsequence/core": "0.0.0-20241114193556", | ||
"@0xsequence/indexer": "0.0.0-20241114193556", | ||
"@0xsequence/metadata": "0.0.0-20241114193556", | ||
"@0xsequence/migration": "0.0.0-20241114193556", | ||
"@0xsequence/network": "0.0.0-20241114193556", | ||
"@0xsequence/sessions": "0.0.0-20241114193556", | ||
"@0xsequence/signhub": "0.0.0-20241114193556", | ||
"@0xsequence/utils": "0.0.0-20241114193556", | ||
"@0xsequence/wallet": "0.0.0-20241114193556" | ||
"@0xsequence/abi": "0.0.0-20241216114019", | ||
"@0xsequence/account": "0.0.0-20241216114019", | ||
"@0xsequence/api": "0.0.0-20241216114019", | ||
"@0xsequence/core": "0.0.0-20241216114019", | ||
"@0xsequence/indexer": "0.0.0-20241216114019", | ||
"@0xsequence/metadata": "0.0.0-20241216114019", | ||
"@0xsequence/migration": "0.0.0-20241216114019", | ||
"@0xsequence/network": "0.0.0-20241216114019", | ||
"@0xsequence/sessions": "0.0.0-20241216114019", | ||
"@0xsequence/signhub": "0.0.0-20241216114019", | ||
"@0xsequence/wallet": "0.0.0-20241216114019", | ||
"@0xsequence/utils": "0.0.0-20241216114019" | ||
}, | ||
@@ -36,3 +36,3 @@ "peerDependencies": { | ||
"mockttp": "^3.6.0", | ||
"@0xsequence/tests": "0.0.0-20241114193556" | ||
"@0xsequence/tests": "0.0.0-20241216114019" | ||
}, | ||
@@ -39,0 +39,0 @@ "files": [ |
import { Account } from '@0xsequence/account' | ||
import { SequenceAPIClient } from '@0xsequence/api' | ||
import { GetAuthToken2Return, GetAuthTokenReturn, SequenceAPIClient } from '@0xsequence/api' | ||
import { ETHAuth, Proof } from '@0xsequence/ethauth' | ||
import { Indexer, SequenceIndexer } from '@0xsequence/indexer' | ||
import { Indexer, SequenceIndexer, SequenceIndexerGateway } from '@0xsequence/indexer' | ||
import { SequenceMetadata } from '@0xsequence/metadata' | ||
@@ -23,2 +23,3 @@ import { ChainIdLike, findNetworkConfig } from '@0xsequence/network' | ||
sequenceMetadataUrl: string | ||
sequenceIndexerGatewayUrl: string | ||
} | ||
@@ -60,2 +61,3 @@ | ||
private indexerClients: Map<number, Indexer> = new Map() | ||
private indexerGateway: SequenceIndexerGateway | undefined | ||
@@ -104,3 +106,3 @@ private projectAccessKey?: string | ||
auth(maxTries: number = 5): Promise<SequenceAPIClient> { | ||
auth(maxTries: number = 5, referenceChainId?: ChainIdLike): Promise<SequenceAPIClient> { | ||
if (this._initialAuthRequest) return this._initialAuthRequest | ||
@@ -115,3 +117,3 @@ | ||
try { | ||
jwtAuth = (await this.getJWT(true)).token | ||
jwtAuth = (await this.getJWT(true, referenceChainId)).token | ||
break | ||
@@ -132,3 +134,3 @@ } catch (error) { | ||
private async getJWT(tryAuth: boolean): Promise<SessionJWT> { | ||
private async getJWT(tryAuth: boolean, referenceChainId?: ChainIdLike): Promise<SessionJWT> { | ||
const url = this.settings.sequenceApiUrl | ||
@@ -162,3 +164,8 @@ if (!url) throw Error('No sequence api url') | ||
const authResp = await api.getAuthToken({ ewtString: proofString }) | ||
let authResp: GetAuthToken2Return | GetAuthTokenReturn | ||
if (referenceChainId) { | ||
authResp = await api.getAuthToken2({ ewtString: proofString, chainID: referenceChainId?.toString() }) | ||
} else { | ||
authResp = await api.getAuthToken({ ewtString: proofString }) | ||
} | ||
@@ -275,2 +282,11 @@ if (authResp?.status === true && authResp.jwtToken.length !== 0) { | ||
async getIndexerGateway(tryAuth: boolean = true): Promise<SequenceIndexerGateway> { | ||
if (!this.indexerGateway) { | ||
const jwtAuth = (await this.getJWT(tryAuth)).token | ||
this.indexerGateway = new SequenceIndexerGateway(this.settings.sequenceMetadataUrl, undefined, jwtAuth) | ||
} | ||
return this.indexerGateway | ||
} | ||
private getProofString(key: string): ProofStringPromise { | ||
@@ -277,0 +293,0 @@ // check if we already have or are waiting for a proof string |
@@ -292,3 +292,3 @@ import { ChainId, NetworkConfig, allNetworks, findNetworkConfig } from '@0xsequence/network' | ||
// otherwise the tracker will not know about this account | ||
await account.publishWitness() | ||
await account.publishWitness(undefined, referenceChainId) | ||
@@ -307,3 +307,3 @@ // safety check, the remove tracker should be able to find | ||
servicesObj = new Services(account, services) | ||
servicesObj.auth() // fire and forget | ||
servicesObj.auth(undefined, referenceChainId) // fire and forget | ||
@@ -310,0 +310,0 @@ servicesObj.onAuth(result => { |
124408
2822
+ Added@0xsequence/abi@0.0.0-20241216114019(transitive)
+ Added@0xsequence/account@0.0.0-20241216114019(transitive)
+ Added@0xsequence/api@0.0.0-20241216114019(transitive)
+ Added@0xsequence/core@0.0.0-20241216114019(transitive)
+ Added@0xsequence/indexer@0.0.0-20241216114019(transitive)
+ Added@0xsequence/metadata@0.0.0-20241216114019(transitive)
+ Added@0xsequence/migration@0.0.0-20241216114019(transitive)
+ Added@0xsequence/network@0.0.0-20241216114019(transitive)
+ Added@0xsequence/relayer@0.0.0-20241216114019(transitive)
+ Added@0xsequence/replacer@0.0.0-20241216114019(transitive)
+ Added@0xsequence/sessions@0.0.0-20241216114019(transitive)
+ Added@0xsequence/signhub@0.0.0-20241216114019(transitive)
+ Added@0xsequence/utils@0.0.0-20241216114019(transitive)
+ Added@0xsequence/wallet@0.0.0-20241216114019(transitive)
- Removed@0xsequence/abi@0.0.0-20241114193556(transitive)
- Removed@0xsequence/account@0.0.0-20241114193556(transitive)
- Removed@0xsequence/api@0.0.0-20241114193556(transitive)
- Removed@0xsequence/core@0.0.0-20241114193556(transitive)
- Removed@0xsequence/indexer@0.0.0-20241114193556(transitive)
- Removed@0xsequence/metadata@0.0.0-20241114193556(transitive)
- Removed@0xsequence/migration@0.0.0-20241114193556(transitive)
- Removed@0xsequence/network@0.0.0-20241114193556(transitive)
- Removed@0xsequence/relayer@0.0.0-20241114193556(transitive)
- Removed@0xsequence/replacer@0.0.0-20241114193556(transitive)
- Removed@0xsequence/sessions@0.0.0-20241114193556(transitive)
- Removed@0xsequence/signhub@0.0.0-20241114193556(transitive)
- Removed@0xsequence/utils@0.0.0-20241114193556(transitive)
- Removed@0xsequence/wallet@0.0.0-20241114193556(transitive)