|
5 | 5 | parseLitResource, |
6 | 6 | } from '@lit-protocol/auth-helpers'; |
7 | 7 | import { RESOLVED_AUTH_CONTEXT_PREFIX } from '@lit-protocol/auth-helpers'; |
| 8 | +import { SiweMessage } from 'siwe'; |
8 | 9 | import { |
9 | 10 | AUTH_METHOD_TYPE, |
10 | 11 | AUTH_METHOD_TYPE_VALUES, |
@@ -292,29 +293,24 @@ function extractAuthConfigFromDelegationAuthSig(delegationAuthSig: AuthSig): { |
292 | 293 | } { |
293 | 294 | const siweMessage = delegationAuthSig.signedMessage; |
294 | 295 |
|
295 | | - // const parsedSiweMessage = new SiweMessage(siweMessage); |
296 | | - |
297 | | - // Extract domain |
298 | | - const domainMatch = siweMessage.match(/^([^\s]+) wants you to sign in/m); |
299 | | - const domain = domainMatch ? domainMatch[1] : undefined; |
| 296 | + const parsedSiweMessage = new SiweMessage(siweMessage); |
| 297 | + const domain = parsedSiweMessage.domain; |
300 | 298 |
|
301 | 299 | // Extract statement |
302 | | - const statementMatch = siweMessage.match(/^(.*?)(?:\n\nURI:|$)/m); |
303 | | - const statement = statementMatch |
304 | | - ? statementMatch[1].split('\n').slice(2).join('\n').trim() |
305 | | - : undefined; |
| 300 | + const statement = parsedSiweMessage.statement; |
306 | 301 |
|
307 | 302 | // Extract expiration |
308 | | - const expirationMatch = siweMessage.match(/^Expiration Time: (.*)$/m); |
309 | | - const expiration = expirationMatch ? expirationMatch[1].trim() : undefined; |
| 303 | + const expiration = parsedSiweMessage.expirationTime; |
310 | 304 |
|
311 | | - const resourceMatches = [...siweMessage.matchAll(/-\s*(urn:recap:[^\s]+)/g)]; |
| 305 | + const resourceMatches = parsedSiweMessage.resources ?? []; |
312 | 306 |
|
313 | 307 | const resources: LitResourceAbilityRequest[] = []; |
314 | 308 | let derivedAuthData: AuthData | undefined; |
315 | 309 |
|
316 | | - for (const match of resourceMatches) { |
317 | | - const urn = match[1]; |
| 310 | + for (const urn of resourceMatches) { |
| 311 | + if (!urn.startsWith('urn:recap:')) { |
| 312 | + continue; |
| 313 | + } |
318 | 314 | const { requests, derivedAuthData: candidateAuthData } = |
319 | 315 | decodeRecapResource(urn); |
320 | 316 |
|
|
0 commit comments