Skip to content

Commit

Permalink
Michael's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Sep 1, 2023
1 parent f2db8bb commit 043a4a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 5 additions & 8 deletions packages/auth/src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ export type SessionJWT = {
expiration: number
}

type SessionJWTPromise = {
export type SessionJWTPromise = {
token: Promise<string>
expiration: number
}

type ProofStringPromise = {
export type ProofStringPromise = {
proofString: Promise<string>
expiration: number
}

function getJWTExpiration(jwt: string): number {
return jwtDecodeClaims<{ exp: number }>(jwt).exp
}

// Default session expiration of ETHAuth token (1 week)
export const DEFAULT_SESSION_EXPIRATION = 60 * 60 * 24 * 7

Expand Down Expand Up @@ -83,6 +79,7 @@ export class Services {

onAuth(cb: (result: PromiseSettledResult<void>) => void) {
this.onAuthCallbacks.push(cb)
return () => this.onAuthCallbacks = this.onAuthCallbacks.filter(c => c !== cb)
}

async dump(): Promise<{
Expand All @@ -108,12 +105,12 @@ export class Services {
if (!url) throw Error('No sequence api url')

let jwtAuth: string | undefined
for (let i = 0; ; i++) {
for (let i = 1; ; i++) {
try {
jwtAuth = (await this.getJWT(true)).token
break
} catch (error) {
if (i === maxTries - 1) {
if (i === maxTries) {
console.error(`couldn't authenticate after ${maxTries} attempts`, error)
throw error
}
Expand Down
10 changes: 7 additions & 3 deletions packages/auth/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ export class Session {
}))

for (const config of configs) {
const coder = config.config && universal.genericCoderFor(config.config.version)
const signers = coder && config.config && coder.config.signersOf(config.config)
if (!config.config) {
continue
}

if (signers && signers.length === 1 && signers[0].address === referenceSigner) {
const coder = universal.genericCoderFor(config.config.version)
const signers = coder.config.signersOf(config.config)

if (signers.length === 1 && signers[0].address === referenceSigner) {
return config.wallet
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class Wallet<
return this.signTransactions(bundle.transactions, bundle.nonce)
}

async nonceFor(
async fetchNonceOrSpace(
nonce?: ethers.BigNumberish | { space: ethers.BigNumberish }
): Promise<ethers.BigNumberish> {
let spaceValue
Expand Down Expand Up @@ -315,7 +315,7 @@ export class Wallet<
})
}

const defaultedNonce = await this.nonceFor(nonce)
const defaultedNonce = await this.fetchNonceOrSpace(nonce)
const digest = commons.transaction.digestOfTransactions(defaultedNonce, transactions)
const signature = await this.signDigest(digest, { transactions })

Expand Down

0 comments on commit 043a4a1

Please sign in to comment.