diff --git a/packages/auth/package.json b/packages/auth/package.json index ede95f236..bbc42f111 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -13,7 +13,9 @@ "author": "yknl ", "homepage": "https://blockstack.org", "license": "GPL-3.0-or-later", - "main": "lib/index.js", + "main": "./dist/index.js", + "umd:main": "./dist/auth.umd.production.js", + "module": "./dist/auth.esm.js", "directories": { "lib": "lib", "test": "__tests__" @@ -26,7 +28,12 @@ "url": "git+https://github.com/blockstack/blockstack.js.git" }, "scripts": { - "build": "rimraf lib && tsc -b tsconfig.build.json", + "build": "cross-env NODE_ENV=production tsdx build --format=cjs,esm,umd", + "build-all": "run-p build:*", + "build:cjs": "tsc --outDir ./lib -m commonjs -t es2017", + "build:esm": "tsc --outDir ./lib-esm -m es6 -t es2017", + "build:cjs:watch": "tsc --outDir ./lib -m commonjs -t es2017 --watch", + "build:esm:watch": "tsc --outDir ./lib-esm -m es6 -t es2017 --watch", "test": "echo \"Error: run tests from root\" && exit 1" }, "bugs": { @@ -35,6 +42,8 @@ "dependencies": { "@stacks/common": "^1.0.0", "@stacks/encryption": "^1.0.0", + "@stacks/network": "^1.0.0", + "@stacks/profile": "^1.0.0", "cross-fetch": "^3.0.5", "jsontokens": "^3.0.0", "query-string": "^6.13.1" diff --git a/packages/auth/src/auth.ts b/packages/auth/src/auth.ts index a18f6e5ea..06febce7d 100644 --- a/packages/auth/src/auth.ts +++ b/packages/auth/src/auth.ts @@ -14,11 +14,10 @@ import { decryptPrivateKey } from './messages' import { NAME_LOOKUP_PATH } from './constants' -import { extractProfile } from './legacy/profiles/profileTokens' +import { extractProfile } from '@stacks/profile' import { UserSession } from './userSession' -import { config } from './legacy/config' -// import { GaiaHubConfig } from './legacy/storage/hub' import { hexStringToECPair } from '@stacks/encryption' +import { StacksMainnet } from '@stacks/network' const DEFAULT_PROFILE = { @@ -130,23 +129,27 @@ export async function handlePendingSignIn( if (!nameLookupURL) { let coreNode = caller.appConfig && caller.appConfig.coreNode if (!coreNode) { - coreNode = config.network.blockstackAPIUrl + let network = new StacksMainnet() + coreNode = network.coreApiUrl } const tokenPayload = decodeToken(authResponseToken).payload if (typeof tokenPayload === 'string') { throw new Error('Unexpected token payload type of string') } - if (isLaterVersion(tokenPayload.version as string, '1.3.0') - && tokenPayload.blockstackAPIUrl !== null && tokenPayload.blockstackAPIUrl !== undefined) { - // override globally - Logger.info(`Overriding ${config.network.blockstackAPIUrl} ` - + `with ${tokenPayload.blockstackAPIUrl}`) - // TODO: this config is never saved so the user node preference - // is not respected in later sessions.. - config.network.blockstackAPIUrl = tokenPayload.blockstackAPIUrl as string - coreNode = tokenPayload.blockstackAPIUrl as string - } + + // Section below is removed since the config was never persisted and therefore useless + + // if (isLaterVersion(tokenPayload.version as string, '1.3.0') + // && tokenPayload.blockstackAPIUrl !== null && tokenPayload.blockstackAPIUrl !== undefined) { + // // override globally + // Logger.info(`Overriding ${config.network.blockstackAPIUrl} ` + // + `with ${tokenPayload.blockstackAPIUrl}`) + // // TODO: this config is never saved so the user node preference + // // is not respected in later sessions.. + // config.network.blockstackAPIUrl = tokenPayload.blockstackAPIUrl as string + // coreNode = tokenPayload.blockstackAPIUrl as string + // } nameLookupURL = `${coreNode}${NAME_LOOKUP_PATH}` } diff --git a/packages/auth/src/legacy/config.ts b/packages/auth/src/legacy_delete/config.ts similarity index 100% rename from packages/auth/src/legacy/config.ts rename to packages/auth/src/legacy_delete/config.ts diff --git a/packages/auth/src/legacy/encryption/aesCipher.ts b/packages/auth/src/legacy_delete/encryption/aesCipher.ts similarity index 100% rename from packages/auth/src/legacy/encryption/aesCipher.ts rename to packages/auth/src/legacy_delete/encryption/aesCipher.ts diff --git a/packages/auth/src/legacy/encryption/cryptoRandom.ts b/packages/auth/src/legacy_delete/encryption/cryptoRandom.ts similarity index 100% rename from packages/auth/src/legacy/encryption/cryptoRandom.ts rename to packages/auth/src/legacy_delete/encryption/cryptoRandom.ts diff --git a/packages/auth/src/legacy/encryption/cryptoUtils.ts b/packages/auth/src/legacy_delete/encryption/cryptoUtils.ts similarity index 100% rename from packages/auth/src/legacy/encryption/cryptoUtils.ts rename to packages/auth/src/legacy_delete/encryption/cryptoUtils.ts diff --git a/packages/auth/src/legacy/encryption/ec.ts b/packages/auth/src/legacy_delete/encryption/ec.ts similarity index 99% rename from packages/auth/src/legacy/encryption/ec.ts rename to packages/auth/src/legacy_delete/encryption/ec.ts index f0bc3a587..0e1834d12 100644 --- a/packages/auth/src/legacy/encryption/ec.ts +++ b/packages/auth/src/legacy_delete/encryption/ec.ts @@ -2,7 +2,7 @@ import { ec as EllipticCurve } from 'elliptic' import * as BN from 'bn.js' import { randomBytes } from './cryptoRandom' import { FailedDecryptionError } from '../errors' -import { getPublicKeyFromPrivate } from '../keys' +import { getPublicKeyFromPrivate } from '@stacks/encryption' import { hashSha256Sync, hashSha512Sync } from './sha2Hash' import { createHmacSha256 } from './hmacSha256' import { createCipher } from './aesCipher' diff --git a/packages/auth/src/legacy/encryption/hashRipemd160.ts b/packages/auth/src/legacy_delete/encryption/hashRipemd160.ts similarity index 100% rename from packages/auth/src/legacy/encryption/hashRipemd160.ts rename to packages/auth/src/legacy_delete/encryption/hashRipemd160.ts diff --git a/packages/auth/src/legacy/encryption/hmacSha256.ts b/packages/auth/src/legacy_delete/encryption/hmacSha256.ts similarity index 100% rename from packages/auth/src/legacy/encryption/hmacSha256.ts rename to packages/auth/src/legacy_delete/encryption/hmacSha256.ts diff --git a/packages/auth/src/legacy/encryption/index.ts b/packages/auth/src/legacy_delete/encryption/index.ts similarity index 100% rename from packages/auth/src/legacy/encryption/index.ts rename to packages/auth/src/legacy_delete/encryption/index.ts diff --git a/packages/auth/src/legacy/encryption/pbkdf2.ts b/packages/auth/src/legacy_delete/encryption/pbkdf2.ts similarity index 100% rename from packages/auth/src/legacy/encryption/pbkdf2.ts rename to packages/auth/src/legacy_delete/encryption/pbkdf2.ts diff --git a/packages/auth/src/legacy/encryption/sha2Hash.ts b/packages/auth/src/legacy_delete/encryption/sha2Hash.ts similarity index 100% rename from packages/auth/src/legacy/encryption/sha2Hash.ts rename to packages/auth/src/legacy_delete/encryption/sha2Hash.ts diff --git a/packages/auth/src/legacy/encryption/wallet.ts b/packages/auth/src/legacy_delete/encryption/wallet.ts similarity index 100% rename from packages/auth/src/legacy/encryption/wallet.ts rename to packages/auth/src/legacy_delete/encryption/wallet.ts diff --git a/packages/auth/src/legacy/errors.ts b/packages/auth/src/legacy_delete/errors.ts similarity index 100% rename from packages/auth/src/legacy/errors.ts rename to packages/auth/src/legacy_delete/errors.ts diff --git a/packages/auth/src/legacy/fetchUtil.ts b/packages/auth/src/legacy_delete/fetchUtil.ts similarity index 100% rename from packages/auth/src/legacy/fetchUtil.ts rename to packages/auth/src/legacy_delete/fetchUtil.ts diff --git a/packages/auth/src/legacy/index.ts b/packages/auth/src/legacy_delete/index.ts similarity index 100% rename from packages/auth/src/legacy/index.ts rename to packages/auth/src/legacy_delete/index.ts diff --git a/packages/auth/src/legacy/keys.ts b/packages/auth/src/legacy_delete/keys.ts similarity index 100% rename from packages/auth/src/legacy/keys.ts rename to packages/auth/src/legacy_delete/keys.ts diff --git a/packages/auth/src/legacy/logger.ts b/packages/auth/src/legacy_delete/logger.ts similarity index 100% rename from packages/auth/src/legacy/logger.ts rename to packages/auth/src/legacy_delete/logger.ts diff --git a/packages/auth/src/legacy/network.ts b/packages/auth/src/legacy_delete/network.ts similarity index 100% rename from packages/auth/src/legacy/network.ts rename to packages/auth/src/legacy_delete/network.ts diff --git a/packages/auth/src/legacy/operations/index.ts b/packages/auth/src/legacy_delete/operations/index.ts similarity index 100% rename from packages/auth/src/legacy/operations/index.ts rename to packages/auth/src/legacy_delete/operations/index.ts diff --git a/packages/auth/src/legacy/operations/safety.ts b/packages/auth/src/legacy_delete/operations/safety.ts similarity index 100% rename from packages/auth/src/legacy/operations/safety.ts rename to packages/auth/src/legacy_delete/operations/safety.ts diff --git a/packages/auth/src/legacy/operations/signers.ts b/packages/auth/src/legacy_delete/operations/signers.ts similarity index 100% rename from packages/auth/src/legacy/operations/signers.ts rename to packages/auth/src/legacy_delete/operations/signers.ts diff --git a/packages/auth/src/legacy/operations/skeletons.ts b/packages/auth/src/legacy_delete/operations/skeletons.ts similarity index 100% rename from packages/auth/src/legacy/operations/skeletons.ts rename to packages/auth/src/legacy_delete/operations/skeletons.ts diff --git a/packages/auth/src/legacy/operations/txbuild.ts b/packages/auth/src/legacy_delete/operations/txbuild.ts similarity index 100% rename from packages/auth/src/legacy/operations/txbuild.ts rename to packages/auth/src/legacy_delete/operations/txbuild.ts diff --git a/packages/auth/src/legacy/operations/utils.ts b/packages/auth/src/legacy_delete/operations/utils.ts similarity index 100% rename from packages/auth/src/legacy/operations/utils.ts rename to packages/auth/src/legacy_delete/operations/utils.ts diff --git a/packages/auth/src/legacy/profiles/index.ts b/packages/auth/src/legacy_delete/profiles/index.ts similarity index 100% rename from packages/auth/src/legacy/profiles/index.ts rename to packages/auth/src/legacy_delete/profiles/index.ts diff --git a/packages/auth/src/legacy/profiles/profile.ts b/packages/auth/src/legacy_delete/profiles/profile.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profile.ts rename to packages/auth/src/legacy_delete/profiles/profile.ts diff --git a/packages/auth/src/legacy/profiles/profileLookup.ts b/packages/auth/src/legacy_delete/profiles/profileLookup.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileLookup.ts rename to packages/auth/src/legacy_delete/profiles/profileLookup.ts diff --git a/packages/auth/src/legacy/profiles/profileProofs.ts b/packages/auth/src/legacy_delete/profiles/profileProofs.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileProofs.ts rename to packages/auth/src/legacy_delete/profiles/profileProofs.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/creativework.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/creativework.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/creativework.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/creativework.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/index.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/index.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/index.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/index.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/organization.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/organization.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/organization.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/organization.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/person.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/person.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/person.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/person.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/personLegacy.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/personLegacy.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/personLegacy.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/personLegacy.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/personUtils.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/personUtils.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/personUtils.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/personUtils.ts diff --git a/packages/auth/src/legacy/profiles/profileSchemas/personZoneFiles.ts b/packages/auth/src/legacy_delete/profiles/profileSchemas/personZoneFiles.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileSchemas/personZoneFiles.ts rename to packages/auth/src/legacy_delete/profiles/profileSchemas/personZoneFiles.ts diff --git a/packages/auth/src/legacy/profiles/profileTokens.ts b/packages/auth/src/legacy_delete/profiles/profileTokens.ts similarity index 99% rename from packages/auth/src/legacy/profiles/profileTokens.ts rename to packages/auth/src/legacy_delete/profiles/profileTokens.ts index e0fdc9fc8..f987d7239 100644 --- a/packages/auth/src/legacy/profiles/profileTokens.ts +++ b/packages/auth/src/legacy_delete/profiles/profileTokens.ts @@ -2,7 +2,7 @@ import { ECPair } from 'bitcoinjs-lib' import { decodeToken, SECP256K1Client, TokenSigner, TokenVerifier } from 'jsontokens' import { TokenInterface } from 'jsontokens/lib/decode' import { nextYear, makeUUID4 } from '@stacks/common' -import { ecPairToAddress } from '../keys' +import { ecPairToAddress } from '@stacks/encryption' /** * Signs a profile token diff --git a/packages/auth/src/legacy/profiles/profileZoneFiles.ts b/packages/auth/src/legacy_delete/profiles/profileZoneFiles.ts similarity index 100% rename from packages/auth/src/legacy/profiles/profileZoneFiles.ts rename to packages/auth/src/legacy_delete/profiles/profileZoneFiles.ts diff --git a/packages/auth/src/legacy/profiles/services/facebook.ts b/packages/auth/src/legacy_delete/profiles/services/facebook.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/facebook.ts rename to packages/auth/src/legacy_delete/profiles/services/facebook.ts diff --git a/packages/auth/src/legacy/profiles/services/github.ts b/packages/auth/src/legacy_delete/profiles/services/github.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/github.ts rename to packages/auth/src/legacy_delete/profiles/services/github.ts diff --git a/packages/auth/src/legacy/profiles/services/hackerNews.ts b/packages/auth/src/legacy_delete/profiles/services/hackerNews.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/hackerNews.ts rename to packages/auth/src/legacy_delete/profiles/services/hackerNews.ts diff --git a/packages/auth/src/legacy/profiles/services/index.ts b/packages/auth/src/legacy_delete/profiles/services/index.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/index.ts rename to packages/auth/src/legacy_delete/profiles/services/index.ts diff --git a/packages/auth/src/legacy/profiles/services/instagram.ts b/packages/auth/src/legacy_delete/profiles/services/instagram.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/instagram.ts rename to packages/auth/src/legacy_delete/profiles/services/instagram.ts diff --git a/packages/auth/src/legacy/profiles/services/linkedIn.ts b/packages/auth/src/legacy_delete/profiles/services/linkedIn.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/linkedIn.ts rename to packages/auth/src/legacy_delete/profiles/services/linkedIn.ts diff --git a/packages/auth/src/legacy/profiles/services/service.ts b/packages/auth/src/legacy_delete/profiles/services/service.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/service.ts rename to packages/auth/src/legacy_delete/profiles/services/service.ts diff --git a/packages/auth/src/legacy/profiles/services/serviceUtils.ts b/packages/auth/src/legacy_delete/profiles/services/serviceUtils.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/serviceUtils.ts rename to packages/auth/src/legacy_delete/profiles/services/serviceUtils.ts diff --git a/packages/auth/src/legacy/profiles/services/twitter.ts b/packages/auth/src/legacy_delete/profiles/services/twitter.ts similarity index 100% rename from packages/auth/src/legacy/profiles/services/twitter.ts rename to packages/auth/src/legacy_delete/profiles/services/twitter.ts diff --git a/packages/auth/src/legacy/public.ts b/packages/auth/src/legacy_delete/public.ts similarity index 75% rename from packages/auth/src/legacy/public.ts rename to packages/auth/src/legacy_delete/public.ts index a4342d8ee..768aae4e8 100644 --- a/packages/auth/src/legacy/public.ts +++ b/packages/auth/src/legacy_delete/public.ts @@ -4,11 +4,6 @@ export { makeDIDFromAddress, makeDIDFromPublicKey, getDIDType, getAddressFromDID } from '../dids' -export { - getEntropy, makeECPrivateKey, publicKeyToAddress, getPublicKeyFromPrivate, - hexStringToECPair, ecPairToHexString, ecPairToAddress -} from './keys' - export { transactions, safety, TransactionSigner, PubkeyHashSigner, addUTXOsToFund, estimateTXBytes diff --git a/packages/auth/src/legacy/wallet.ts b/packages/auth/src/legacy_delete/wallet.ts similarity index 99% rename from packages/auth/src/legacy/wallet.ts rename to packages/auth/src/legacy_delete/wallet.ts index 958c15d07..09c012ccb 100644 --- a/packages/auth/src/legacy/wallet.ts +++ b/packages/auth/src/legacy_delete/wallet.ts @@ -4,7 +4,7 @@ import { encryptMnemonic, decryptMnemonic } from './encryption/wallet' import { randomBytes, GetRandomBytes } from './encryption/cryptoRandom' import { hashSha256Sync } from './encryption/sha2Hash' import { TriplesecDecryptSignature } from './encryption/cryptoUtils' -import { ecPairToHexString } from './keys' +import { ecPairToHexString } from '@stacks/encryption' const APPS_NODE_INDEX = 0 const IDENTITY_KEYCHAIN = 888 diff --git a/packages/auth/src/messages.ts b/packages/auth/src/messages.ts index 0415392e1..d6a0f60bc 100644 --- a/packages/auth/src/messages.ts +++ b/packages/auth/src/messages.ts @@ -2,10 +2,9 @@ import 'cross-fetch/polyfill' import { TokenSigner, SECP256K1Client } from 'jsontokens' -import { makeECPrivateKey, publicKeyToAddress } from './legacy/keys' import { makeUUID4, nextMonth, getGlobalObject, Logger } from '@stacks/common' import { makeDIDFromAddress } from './dids' -import { encryptECIES, decryptECIES } from './legacy/encryption/ec' +import { encryptECIES, decryptECIES, makeECPrivateKey, publicKeyToAddress } from '@stacks/encryption' import { DEFAULT_SCOPE, AuthScope } from './constants' import { UserSession } from './userSession' diff --git a/packages/auth/src/profile.ts b/packages/auth/src/profile.ts index c44344104..36adc007c 100644 --- a/packages/auth/src/profile.ts +++ b/packages/auth/src/profile.ts @@ -1,7 +1,13 @@ -import { resolveZoneFileToProfile } from './legacy/profiles/profileZoneFiles' -import { fetchPrivate } from '@stacks/common' -import { config } from './legacy/config' +import { resolveZoneFileToProfile } from '@stacks/profile' +import { fetchPrivate} from '@stacks/common' +import { StacksNetwork, StacksMainnet } from '@stacks/network' + +export interface ProfileLookupOptions { + username: string; + zoneFileLookupURL?: string; + network?: StacksNetwork; +} /** * Look up a user profile by blockstack ID @@ -12,21 +18,21 @@ import { config } from './legacy/config' * blockstack.js [[getNameInfo]] function. * @returns {Promise} that resolves to a profile object */ -export function lookupProfile(username: string, zoneFileLookupURL?: string): - Promise> { - if (!username) { +export function lookupProfile(options: ProfileLookupOptions): Promise> { + if (!options.username) { return Promise.reject() } + let network: StacksNetwork = options.network ? options.network : new StacksMainnet let lookupPromise - if (zoneFileLookupURL) { - const url = `${zoneFileLookupURL.replace(/\/$/, '')}/${username}` + if (options.zoneFileLookupURL) { + const url = `${options.zoneFileLookupURL.replace(/\/$/, '')}/${options.username}` lookupPromise = fetchPrivate(url) .then(response => response.json()) } else { - lookupPromise = config.network.getNameInfo(username) + lookupPromise = network.getNameInfo(options.username) } return lookupPromise - .then((responseJSON) => { + .then((responseJSON: any) => { if (responseJSON.hasOwnProperty('zonefile') && responseJSON.hasOwnProperty('address')) { return resolveZoneFileToProfile(responseJSON.zonefile, responseJSON.address) @@ -35,4 +41,4 @@ export function lookupProfile(username: string, zoneFileLookupURL?: string): + ' or `zonefile` field') } }) -} +} \ No newline at end of file diff --git a/packages/auth/src/sessionData.ts b/packages/auth/src/sessionData.ts index 9a091d87f..7f1658652 100644 --- a/packages/auth/src/sessionData.ts +++ b/packages/auth/src/sessionData.ts @@ -1,5 +1,3 @@ - -// import { GaiaHubConfig } from './legacy/storage/hub' import { InvalidStateError } from '@stacks/common' import { UserData } from './auth' diff --git a/packages/auth/src/userSession.ts b/packages/auth/src/userSession.ts index 48c4af90b..0d99f122d 100644 --- a/packages/auth/src/userSession.ts +++ b/packages/auth/src/userSession.ts @@ -7,7 +7,6 @@ import { } from './sessionStore' import * as authMessages from './messages' -// import * as storage from './legacy/storage' import { nextHour, diff --git a/packages/auth/src/verification.ts b/packages/auth/src/verification.ts index 447911aa6..a86d5230f 100644 --- a/packages/auth/src/verification.ts +++ b/packages/auth/src/verification.ts @@ -1,6 +1,6 @@ import { decodeToken, TokenVerifier } from 'jsontokens' import { getAddressFromDID } from './dids' -import { publicKeyToAddress } from './legacy/keys' +import { publicKeyToAddress } from '@stacks/encryption' import { fetchPrivate, isSameOriginAbsoluteUrl } from '@stacks/common' import { fetchAppManifest } from './provider' diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json new file mode 100644 index 000000000..872e43ff7 --- /dev/null +++ b/packages/auth/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "./src/**/*" + ] +} \ No newline at end of file