import * as queryString from 'query-string' ; import { decodeToken } from 'jsontokens' ; import { BLOCKSTACK_HANDLER , getGlobalObject , fetchPrivate } from '@stacks/common' ; return { String | null } private ignore export function getAuthRequestFromURL ( ) { const location = getGlobalObject ( 'location' , { throwIfUnavailable : true , usageDesc : 'getAuthRequestFromURL' , } ) ; if ( location ?. search ) { const queryDict = queryString . parse ( location ?. search ) ; if ( queryDict . authRequest ) { return ( queryDict . authRequest as string ) . split ( `${ BLOCKSTACK_HANDLER }:` ) . join ( '' ) ; } else { return null ; } } else { return null ; } } param { String } authRequest return { Promise < Object | String > } private ignore export async function fetchAppManifest ( authRequest ) { if ( ! authRequest ) { throw new Error ( 'Invalid auth request' ) ; } const payload = decodeToken ( authRequest ) . payload ; if ( typeof payload === 'string' ) { throw new Error ( 'Unexpected token payload type of string' ) ; } const manifestURI = payload . manifest_uri as string ; try { const response = await fetchPrivate ( manifestURI ) ; const responseText = await response . text ( ) ; const responseJSON = JSON . parse ( responseText ) ; return { ... responseJSON , manifestURI } ; } catch ( error ) { console . log ( error ) ; throw new Error ( 'Could not fetch manifest.json' ) ; } }