@stacks/auth
Advanced tools
Comparing version 6.14.0-beta.0 to 6.14.1-next.31
@@ -1,7 +0,10 @@ | ||
import { StacksNetwork, StacksNetworkName } from '@stacks/network'; | ||
import { ApiOpts, ApiParam } from '@stacks/common'; | ||
export interface ProfileLookupOptions { | ||
username: string; | ||
zoneFileLookupURL?: string; | ||
network?: StacksNetworkName | StacksNetwork; | ||
api?: ApiOpts; | ||
} | ||
export declare function lookupProfile(lookupOptions: ProfileLookupOptions): Promise<Record<string, any>>; | ||
export declare function lookupProfile(options: ProfileLookupOptions): Promise<Record<string, any>>; | ||
export declare function getNameInfo(opts: { | ||
name: string; | ||
} & ApiParam): Promise<any>; |
@@ -0,23 +1,23 @@ | ||
import { defaultApiLike } from '@stacks/common'; | ||
import { resolveZoneFileToProfile } from '@stacks/profile'; | ||
import { StacksMainnet, StacksNetwork } from '@stacks/network'; | ||
export function lookupProfile(lookupOptions) { | ||
if (!lookupOptions.username) { | ||
export function lookupProfile(options) { | ||
if (!options.username) { | ||
return Promise.reject(new Error('No username provided')); | ||
} | ||
const defaultOptions = { | ||
network: new StacksMainnet(), | ||
}; | ||
const options = Object.assign(defaultOptions, lookupOptions); | ||
const network = StacksNetwork.fromNameOrNetwork(options.network); | ||
const api = defaultApiLike(options.api); | ||
let lookupPromise; | ||
if (options.zoneFileLookupURL) { | ||
const url = `${options.zoneFileLookupURL.replace(/\/$/, '')}/${options.username}`; | ||
lookupPromise = network.fetchFn(url).then(response => response.json()); | ||
lookupPromise = api.fetch(url).then(response => response.json()); | ||
} | ||
else { | ||
lookupPromise = network.getNameInfo(options.username); | ||
lookupPromise = getNameInfo({ name: options.username, api }); | ||
} | ||
return lookupPromise.then((responseJSON) => { | ||
if (responseJSON.hasOwnProperty('zonefile') && responseJSON.hasOwnProperty('address')) { | ||
return resolveZoneFileToProfile(responseJSON.zonefile, responseJSON.address, network.fetchFn); | ||
return resolveZoneFileToProfile({ | ||
zoneFile: responseJSON.zonefile, | ||
publicKeyOrAddress: responseJSON.address, | ||
api, | ||
}); | ||
} | ||
@@ -29,2 +29,27 @@ else { | ||
} | ||
export function getNameInfo(opts) { | ||
const api = defaultApiLike(opts.api); | ||
const nameLookupURL = `${api.url}/v1/names/${opts.name}`; | ||
return api | ||
.fetch(nameLookupURL) | ||
.then((resp) => { | ||
if (resp.status === 404) { | ||
throw new Error('Name not found'); | ||
} | ||
else if (resp.status !== 200) { | ||
throw new Error(`Bad response status: ${resp.status}`); | ||
} | ||
else { | ||
return resp.json(); | ||
} | ||
}) | ||
.then((nameInfo) => { | ||
if (nameInfo.address) { | ||
return Object.assign({}, nameInfo, { address: nameInfo.address }); | ||
} | ||
else { | ||
return nameInfo; | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=profile.js.map |
@@ -1,3 +0,3 @@ | ||
import { FetchFn } from '@stacks/network'; | ||
import { FetchFn } from '@stacks/common'; | ||
export declare function getAuthRequestFromURL(): string | null; | ||
export declare function fetchAppManifest(authRequest: string, fetchFn?: FetchFn): Promise<any>; |
import { decodeToken } from 'jsontokens'; | ||
import { BLOCKSTACK_HANDLER, getGlobalObject } from '@stacks/common'; | ||
import { createFetchFn } from '@stacks/network'; | ||
import { BLOCKSTACK_HANDLER, createFetchFn, getGlobalObject } from '@stacks/common'; | ||
export function getAuthRequestFromURL() { | ||
@@ -5,0 +4,0 @@ const location = getGlobalObject('location', { |
@@ -5,5 +5,5 @@ import { AppConfig } from './appConfig'; | ||
import { EncryptContentOptions } from '@stacks/encryption'; | ||
import { FetchFn } from '@stacks/common'; | ||
import { AuthScope } from './constants'; | ||
import { UserData } from './userData'; | ||
import { FetchFn } from '@stacks/network'; | ||
export declare class UserSession { | ||
@@ -10,0 +10,0 @@ appConfig: AppConfig; |
@@ -8,6 +8,5 @@ import { AppConfig } from './appConfig'; | ||
import { getAddressFromDID } from './dids'; | ||
import { BLOCKSTACK_DEFAULT_GAIA_HUB_URL, getGlobalObject, InvalidStateError, isLaterVersion, Logger, LoginFailedError, MissingParameterError, nextHour, } from '@stacks/common'; | ||
import { createFetchFn, GAIA_URL, getGlobalObject, HIRO_MAINNET_URL, InvalidStateError, isLaterVersion, Logger, LoginFailedError, MissingParameterError, nextHour, } from '@stacks/common'; | ||
import { extractProfile } from '@stacks/profile'; | ||
import { DEFAULT_PROFILE } from './constants'; | ||
import { createFetchFn, StacksMainnet } from '@stacks/network'; | ||
import { protocolEchoReplyDetection } from './protocolEchoDetection'; | ||
@@ -98,4 +97,3 @@ export class UserSession { | ||
if (!coreNode) { | ||
const network = new StacksMainnet(); | ||
coreNode = network.bnsLookupUrl; | ||
coreNode = HIRO_MAINNET_URL; | ||
} | ||
@@ -139,3 +137,3 @@ const tokenPayload = decodeToken(authResponseToken).payload; | ||
} | ||
let hubUrl = BLOCKSTACK_DEFAULT_GAIA_HUB_URL; | ||
let hubUrl = GAIA_URL; | ||
let gaiaAssociationToken; | ||
@@ -142,0 +140,0 @@ if (isLaterVersion(tokenPayload.version, '1.2.0') && |
@@ -1,7 +0,10 @@ | ||
import { StacksNetwork, StacksNetworkName } from '@stacks/network'; | ||
import { ApiOpts, ApiParam } from '@stacks/common'; | ||
export interface ProfileLookupOptions { | ||
username: string; | ||
zoneFileLookupURL?: string; | ||
network?: StacksNetworkName | StacksNetwork; | ||
api?: ApiOpts; | ||
} | ||
export declare function lookupProfile(lookupOptions: ProfileLookupOptions): Promise<Record<string, any>>; | ||
export declare function lookupProfile(options: ProfileLookupOptions): Promise<Record<string, any>>; | ||
export declare function getNameInfo(opts: { | ||
name: string; | ||
} & ApiParam): Promise<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lookupProfile = void 0; | ||
exports.getNameInfo = exports.lookupProfile = void 0; | ||
const common_1 = require("@stacks/common"); | ||
const profile_1 = require("@stacks/profile"); | ||
const network_1 = require("@stacks/network"); | ||
function lookupProfile(lookupOptions) { | ||
if (!lookupOptions.username) { | ||
function lookupProfile(options) { | ||
if (!options.username) { | ||
return Promise.reject(new Error('No username provided')); | ||
} | ||
const defaultOptions = { | ||
network: new network_1.StacksMainnet(), | ||
}; | ||
const options = Object.assign(defaultOptions, lookupOptions); | ||
const network = network_1.StacksNetwork.fromNameOrNetwork(options.network); | ||
const api = (0, common_1.defaultApiLike)(options.api); | ||
let lookupPromise; | ||
if (options.zoneFileLookupURL) { | ||
const url = `${options.zoneFileLookupURL.replace(/\/$/, '')}/${options.username}`; | ||
lookupPromise = network.fetchFn(url).then(response => response.json()); | ||
lookupPromise = api.fetch(url).then(response => response.json()); | ||
} | ||
else { | ||
lookupPromise = network.getNameInfo(options.username); | ||
lookupPromise = getNameInfo({ name: options.username, api }); | ||
} | ||
return lookupPromise.then((responseJSON) => { | ||
if (responseJSON.hasOwnProperty('zonefile') && responseJSON.hasOwnProperty('address')) { | ||
return (0, profile_1.resolveZoneFileToProfile)(responseJSON.zonefile, responseJSON.address, network.fetchFn); | ||
return (0, profile_1.resolveZoneFileToProfile)({ | ||
zoneFile: responseJSON.zonefile, | ||
publicKeyOrAddress: responseJSON.address, | ||
api, | ||
}); | ||
} | ||
@@ -33,2 +33,28 @@ else { | ||
exports.lookupProfile = lookupProfile; | ||
function getNameInfo(opts) { | ||
const api = (0, common_1.defaultApiLike)(opts.api); | ||
const nameLookupURL = `${api.url}/v1/names/${opts.name}`; | ||
return api | ||
.fetch(nameLookupURL) | ||
.then((resp) => { | ||
if (resp.status === 404) { | ||
throw new Error('Name not found'); | ||
} | ||
else if (resp.status !== 200) { | ||
throw new Error(`Bad response status: ${resp.status}`); | ||
} | ||
else { | ||
return resp.json(); | ||
} | ||
}) | ||
.then((nameInfo) => { | ||
if (nameInfo.address) { | ||
return Object.assign({}, nameInfo, { address: nameInfo.address }); | ||
} | ||
else { | ||
return nameInfo; | ||
} | ||
}); | ||
} | ||
exports.getNameInfo = getNameInfo; | ||
//# sourceMappingURL=profile.js.map |
@@ -1,3 +0,3 @@ | ||
import { FetchFn } from '@stacks/network'; | ||
import { FetchFn } from '@stacks/common'; | ||
export declare function getAuthRequestFromURL(): string | null; | ||
export declare function fetchAppManifest(authRequest: string, fetchFn?: FetchFn): Promise<any>; |
@@ -6,3 +6,2 @@ "use strict"; | ||
const common_1 = require("@stacks/common"); | ||
const network_1 = require("@stacks/network"); | ||
function getAuthRequestFromURL() { | ||
@@ -17,3 +16,3 @@ const location = (0, common_1.getGlobalObject)('location', { | ||
exports.getAuthRequestFromURL = getAuthRequestFromURL; | ||
async function fetchAppManifest(authRequest, fetchFn = (0, network_1.createFetchFn)()) { | ||
async function fetchAppManifest(authRequest, fetchFn = (0, common_1.createFetchFn)()) { | ||
if (!authRequest) { | ||
@@ -20,0 +19,0 @@ throw new Error('Invalid auth request'); |
@@ -5,5 +5,5 @@ import { AppConfig } from './appConfig'; | ||
import { EncryptContentOptions } from '@stacks/encryption'; | ||
import { FetchFn } from '@stacks/common'; | ||
import { AuthScope } from './constants'; | ||
import { UserData } from './userData'; | ||
import { FetchFn } from '@stacks/network'; | ||
export declare class UserSession { | ||
@@ -10,0 +10,0 @@ appConfig: AppConfig; |
@@ -37,3 +37,2 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const network_1 = require("@stacks/network"); | ||
const protocolEchoDetection_1 = require("./protocolEchoDetection"); | ||
@@ -116,3 +115,3 @@ class UserSession { | ||
} | ||
async handlePendingSignIn(authResponseToken = this.getAuthResponseToken(), fetchFn = (0, network_1.createFetchFn)()) { | ||
async handlePendingSignIn(authResponseToken = this.getAuthResponseToken(), fetchFn = (0, common_1.createFetchFn)()) { | ||
const sessionData = this.store.getSessionData(); | ||
@@ -125,4 +124,3 @@ if (sessionData.userData) { | ||
if (!coreNode) { | ||
const network = new network_1.StacksMainnet(); | ||
coreNode = network.bnsLookupUrl; | ||
coreNode = common_1.HIRO_MAINNET_URL; | ||
} | ||
@@ -166,3 +164,3 @@ const tokenPayload = (0, jsontokens_1.decodeToken)(authResponseToken).payload; | ||
} | ||
let hubUrl = common_1.BLOCKSTACK_DEFAULT_GAIA_HUB_URL; | ||
let hubUrl = common_1.GAIA_URL; | ||
let gaiaAssociationToken; | ||
@@ -169,0 +167,0 @@ if ((0, common_1.isLaterVersion)(tokenPayload.version, '1.2.0') && |
{ | ||
"name": "@stacks/auth", | ||
"version": "6.14.0-beta.0", | ||
"version": "6.14.1-next.31+e618d2f3", | ||
"description": "Authentication for Stacks apps.", | ||
@@ -23,6 +23,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@stacks/common": "^6.14.0-beta.0", | ||
"@stacks/encryption": "^6.14.0-beta.0", | ||
"@stacks/network": "^6.14.0-beta.0", | ||
"@stacks/profile": "^6.14.0-beta.0", | ||
"@stacks/common": "^6.14.1-next.31+e618d2f3", | ||
"@stacks/encryption": "^6.14.1-next.31+e618d2f3", | ||
"@stacks/network": "^6.14.1-next.31+e618d2f3", | ||
"@stacks/profile": "^6.14.1-next.31+e618d2f3", | ||
"cross-fetch": "^3.1.5", | ||
@@ -63,3 +63,3 @@ "jsontokens": "^4.0.1" | ||
}, | ||
"gitHead": "a91f28c64f6201435ee8c7ca328c6c5100ab2f0a" | ||
"gitHead": "e618d2f38d09bddd441311db9fa6cc549f702c4e" | ||
} |
@@ -0,3 +1,3 @@ | ||
import { ApiOpts, ApiParam, defaultApiLike } from '@stacks/common'; | ||
import { resolveZoneFileToProfile } from '@stacks/profile'; | ||
import { StacksMainnet, StacksNetwork, StacksNetworkName } from '@stacks/network'; | ||
@@ -7,3 +7,3 @@ export interface ProfileLookupOptions { | ||
zoneFileLookupURL?: string; | ||
network?: StacksNetworkName | StacksNetwork; | ||
api?: ApiOpts; | ||
} | ||
@@ -20,23 +20,23 @@ | ||
*/ | ||
export function lookupProfile(lookupOptions: ProfileLookupOptions): Promise<Record<string, any>> { | ||
if (!lookupOptions.username) { | ||
export function lookupProfile(options: ProfileLookupOptions): Promise<Record<string, any>> { | ||
if (!options.username) { | ||
return Promise.reject(new Error('No username provided')); | ||
} | ||
const defaultOptions = { | ||
network: new StacksMainnet(), | ||
}; | ||
const options = Object.assign(defaultOptions, lookupOptions); | ||
const api = defaultApiLike(options.api); | ||
const network = StacksNetwork.fromNameOrNetwork(options.network); | ||
let lookupPromise; | ||
if (options.zoneFileLookupURL) { | ||
const url = `${options.zoneFileLookupURL.replace(/\/$/, '')}/${options.username}`; | ||
lookupPromise = network.fetchFn(url).then(response => response.json()); | ||
lookupPromise = api.fetch(url).then(response => response.json()); | ||
} else { | ||
lookupPromise = network.getNameInfo(options.username); | ||
lookupPromise = getNameInfo({ name: options.username, api }); | ||
} | ||
return lookupPromise.then((responseJSON: any) => { | ||
if (responseJSON.hasOwnProperty('zonefile') && responseJSON.hasOwnProperty('address')) { | ||
return resolveZoneFileToProfile(responseJSON.zonefile, responseJSON.address, network.fetchFn); | ||
return resolveZoneFileToProfile({ | ||
zoneFile: responseJSON.zonefile, | ||
publicKeyOrAddress: responseJSON.address, | ||
api, | ||
}); | ||
} else { | ||
@@ -49,1 +49,33 @@ throw new Error( | ||
} | ||
export function getNameInfo( | ||
opts: { | ||
/** Fully qualified name */ | ||
name: string; | ||
} & ApiParam | ||
) { | ||
const api = defaultApiLike(opts.api); | ||
const nameLookupURL = `${api.url}/v1/names/${opts.name}`; | ||
return api | ||
.fetch(nameLookupURL) | ||
.then((resp: any) => { | ||
if (resp.status === 404) { | ||
throw new Error('Name not found'); | ||
} else if (resp.status !== 200) { | ||
throw new Error(`Bad response status: ${resp.status}`); | ||
} else { | ||
return resp.json(); | ||
} | ||
}) | ||
.then((nameInfo: any) => { | ||
// the returned address _should_ be in the correct network --- | ||
// stacks node gets into trouble because it tries to coerce back to mainnet | ||
// and the regtest transaction generation libraries want to use testnet addresses | ||
if (nameInfo.address) { | ||
return Object.assign({}, nameInfo, { address: nameInfo.address }); | ||
} else { | ||
return nameInfo; | ||
} | ||
}); | ||
} |
import { decodeToken } from 'jsontokens'; | ||
import { BLOCKSTACK_HANDLER, getGlobalObject } from '@stacks/common'; | ||
import { createFetchFn, FetchFn } from '@stacks/network'; | ||
import { BLOCKSTACK_HANDLER, FetchFn, createFetchFn, getGlobalObject } from '@stacks/common'; | ||
@@ -5,0 +4,0 @@ /** |
@@ -17,4 +17,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ | ||
import { | ||
BLOCKSTACK_DEFAULT_GAIA_HUB_URL, | ||
createFetchFn, | ||
FetchFn, | ||
GAIA_URL, | ||
getGlobalObject, | ||
HIRO_MAINNET_URL, | ||
InvalidStateError, | ||
@@ -31,3 +34,2 @@ isLaterVersion, | ||
import { UserData } from './userData'; | ||
import { createFetchFn, FetchFn, StacksMainnet } from '@stacks/network'; | ||
import { protocolEchoReplyDetection } from './protocolEchoDetection'; | ||
@@ -230,4 +232,3 @@ | ||
if (!coreNode) { | ||
const network = new StacksMainnet(); | ||
coreNode = network.bnsLookupUrl; | ||
coreNode = HIRO_MAINNET_URL; | ||
} | ||
@@ -283,3 +284,3 @@ | ||
} | ||
let hubUrl = BLOCKSTACK_DEFAULT_GAIA_HUB_URL; | ||
let hubUrl = GAIA_URL; | ||
let gaiaAssociationToken: string; | ||
@@ -286,0 +287,0 @@ if ( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
4129
1309651
2