Skip to content

Commit a2ab290

Browse files
committed
chore: rebase
1 parent e3a159a commit a2ab290

File tree

1 file changed

+62
-26
lines changed

1 file changed

+62
-26
lines changed

src/core/internal/modes/relay.ts

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as Erc8010 from '../erc8010.js'
1919
import * as Mode from '../mode.js'
2020
import * as PermissionsRequest from '../permissionsRequest.js'
2121
import * as RequiredFunds from '../requiredFunds.js'
22+
import type * as Capabilities from '../schema/capabilities.js'
2223
import * as Siwe from '../siwe.js'
2324
import * as Tokens from '../tokens.js'
2425
import * as U from '../utils.js'
@@ -106,10 +107,16 @@ export function relay(parameters: relay.Parameters = {}) {
106107

107108
const signInWithEthereum_response = await (async () => {
108109
if (!signInWithEthereum) return undefined
110+
const resolvedSignInWithEthereum =
111+
resolveSiweDefaults(signInWithEthereum)
109112

110-
const message = await Siwe.buildMessage(client, signInWithEthereum, {
111-
address: account.address,
112-
})
113+
const message = await Siwe.buildMessage(
114+
client,
115+
resolvedSignInWithEthereum,
116+
{
117+
address: account.address,
118+
},
119+
)
113120
const signature = await Account.sign(eoa, {
114121
payload: PersonalMessage.getSignPayload(Hex.fromString(message)),
115122
storage: config.storage,
@@ -120,7 +127,21 @@ export function relay(parameters: relay.Parameters = {}) {
120127
signature,
121128
})
122129

123-
return { message, signature: signature_erc8010 }
130+
// If authUrl is provided, authenticate with the server
131+
const authUrl = signInWithEthereum.authUrl
132+
? Siwe.resolveAuthUrl(signInWithEthereum.authUrl)
133+
: undefined
134+
135+
if (!authUrl) return { message, signature: signature_erc8010 }
136+
137+
const { token } = await Siwe.authenticate({
138+
address: account.address,
139+
authUrl,
140+
message,
141+
signature: signature_erc8010,
142+
})
143+
144+
return { message, signature: signature_erc8010, token }
124145
})()
125146

126147
return {
@@ -346,9 +367,11 @@ export function relay(parameters: relay.Parameters = {}) {
346367
// prepareCalls requires the EOA address, but we don't know it here.
347368
const { digest, digestType, message } = await (async () => {
348369
if (signInWithEthereum && parameters.address) {
370+
const resolvedSignInWithEthereum =
371+
resolveSiweDefaults(signInWithEthereum)
349372
const message = await Siwe.buildMessage(
350373
client,
351-
signInWithEthereum,
374+
resolvedSignInWithEthereum,
352375
{
353376
address: parameters.address,
354377
},
@@ -489,6 +512,8 @@ export function relay(parameters: relay.Parameters = {}) {
489512

490513
const signInWithEthereum_response = await (async () => {
491514
if (!signInWithEthereum) return undefined
515+
const resolvedSignInWithEthereum =
516+
resolveSiweDefaults(signInWithEthereum)
492517

493518
if (digestType === 'siwe' && message && signature) {
494519
const signature_erc8010 = await Erc8010.wrap(client, {
@@ -498,28 +523,39 @@ export function relay(parameters: relay.Parameters = {}) {
498523
return { message, signature: signature_erc8010 }
499524
}
500525

501-
{
502-
const message = await Siwe.buildMessage(
503-
client,
504-
signInWithEthereum,
505-
{
506-
address: account.address,
507-
},
508-
)
509-
const signature = await Account.sign(account, {
510-
payload: PersonalMessage.getSignPayload(Hex.fromString(message)),
511-
role: 'admin',
512-
webAuthn,
513-
})
514-
const signature_erc8010 = await Erc8010.wrap(client, {
526+
const message_ = await Siwe.buildMessage(
527+
client,
528+
resolvedSignInWithEthereum,
529+
{
515530
address: account.address,
516-
signature,
517-
})
518-
return {
519-
message,
520-
signature: signature_erc8010,
521-
}
522-
}
531+
},
532+
)
533+
const signature_ = await Account.sign(account, {
534+
payload: PersonalMessage.getSignPayload(Hex.fromString(message_)),
535+
role: 'admin',
536+
webAuthn,
537+
})
538+
const signature_erc8010 = await Erc8010.wrap(client, {
539+
address: account.address,
540+
signature: signature_,
541+
})
542+
543+
// If authUrl is provided, authenticate with the server
544+
const authUrl = signInWithEthereum.authUrl
545+
? Siwe.resolveAuthUrl(signInWithEthereum.authUrl)
546+
: undefined
547+
548+
if (!authUrl)
549+
return { message: message_, signature: signature_erc8010 }
550+
551+
const { token } = await Siwe.authenticate({
552+
address: account.address,
553+
authUrl,
554+
message: message_,
555+
signature: signature_erc8010,
556+
})
557+
558+
return { message: message_, signature: signature_erc8010, token }
523559
})()
524560

525561
return {

0 commit comments

Comments
 (0)