diff --git a/packages/auth/tests/sampleData.ts b/packages/auth/tests/sampleData.ts index b3bd8cd7..2ab17ac4 100644 --- a/packages/auth/tests/sampleData.ts +++ b/packages/auth/tests/sampleData.ts @@ -2,24 +2,6 @@ import * as fs from 'fs' const TEST_DATA_DIR = './tests/testData' -export const sampleManifests = { - helloBlockstack: { - name: 'Hello, Blockstack', - short_name: 'Hello, Blockstack', - start_url: 'https://helloblockstack.com', - display: 'standalone', - background_color: '#fff', - description: 'A simple app demonstrating how to log in with Blockstack.', - icons: [ - { - src: 'https://raw.githubusercontent.com/blockstack/blockstack-portal/master/app/images/app-hello-blockstack.png', - sizes: '192x192', - type: 'image/png' - } - ] - } -} - export const sampleNameRecords = { ryan: JSON.parse(fs.readFileSync(`${TEST_DATA_DIR}/name-records/ryan.json`, 'utf8')) } diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 7756585c..d2a751fc 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -128,24 +128,6 @@ export function getMaxIDSearchIndex() { return maxIDSearchIndex; } -export interface WhoisInfoType { - address: string; - blockchain: string; - block_renewed_at: number; - did: string; - expire_block: number; - grace_period: number; - last_transaction_height: number; - last_txid: string; - owner_address: string; - owner_script: string; - renewal_deadline: number; - resolver: string | null; - status: string; - zonefile: string | null; - zonefile_hash: string | null; -} - /* * Sign a profile. * @path (string) path to the profile diff --git a/packages/cli/src/data.ts b/packages/cli/src/data.ts index e3893b74..8cba31df 100644 --- a/packages/cli/src/data.ts +++ b/packages/cli/src/data.ts @@ -6,13 +6,7 @@ import * as jsontokens from 'jsontokens'; // eslint-disable-next-line @typescript-eslint/no-var-requires const ZoneFile = require('zone-file'); -import { - canonicalPrivateKey, - getPrivateKeyAddress, - checkUrl, - SafetyError, - getPublicKeyFromPrivateKey, -} from './utils'; +import { canonicalPrivateKey, getPrivateKeyAddress, getPublicKeyFromPrivateKey } from './utils'; import { CLINetworkAdapter, NameInfoType } from './network'; @@ -282,48 +276,6 @@ export function gaiaUploadProfileAll( }); } -/* - * Make a zone file from a Gaia hub---reach out to the Gaia hub, get its read URL prefix, - * and generate a zone file with the profile mapped to the Gaia hub. - * - * @network (object) the network connection - * @name (string) the name that owns the zone file - * @gaiaHubUrl (string) the URL to the gaia hub write endpoint - * @ownerKey (string) the owner private key - * - * Returns a promise that resolves to the zone file with the profile URL - */ -export function makeZoneFileFromGaiaUrl( - network: CLINetworkAdapter, - name: string, - gaiaHubUrl: string, - ownerKey: string -) { - const address = getPrivateKeyAddress(network, ownerKey); - const mainnetAddress = network.coerceMainnetAddress(address); - - return gaiaConnect(network, gaiaHubUrl, ownerKey).then(hubConfig => { - if (!hubConfig.url_prefix) { - throw new Error('Invalid hub config: no read_url_prefix defined'); - } - const gaiaReadUrl = hubConfig.url_prefix.replace(/\/+$/, ''); - const profileUrl = `${gaiaReadUrl}/${mainnetAddress}/profile.json`; - try { - checkUrl(profileUrl); - } catch (e) { - throw new SafetyError({ - status: false, - error: e.message, - hints: [ - 'Make sure the Gaia hub read URL scheme is present and well-formed.', - `Check the "read_url_prefix" field of ${gaiaHubUrl}/hub_info`, - ], - }); - } - return blockstack.makeProfileZoneFile(name, profileUrl); - }); -} - /* * Given a Gaia bucket URL, extract its address */ diff --git a/packages/cli/src/keys.ts b/packages/cli/src/keys.ts index 50d02a63..7ad2b332 100644 --- a/packages/cli/src/keys.ts +++ b/packages/cli/src/keys.ts @@ -17,7 +17,6 @@ import { CLINetworkAdapter } from './network'; import * as bip32 from 'bip32'; import { BIP32Interface } from 'bip32'; -export const STRENGTH = 128; // 12 words export const STX_WALLET_COMPATIBLE_SEED_STRENGTH = 256; export const DERIVATION_PATH = "m/44'/5757'/0'/0/0"; diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index fea2a307..2c2400fd 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -1,12 +1,10 @@ import { Buffer } from '@stacks/common'; import * as logger from 'winston'; import * as bitcoinjs from 'bitcoinjs-lib'; -import * as URL from 'url'; import * as readline from 'readline'; import * as stream from 'stream'; import * as fs from 'fs'; import * as blockstack from 'blockstack'; -import { TokenSigner } from 'jsontokens'; import { getTypeString, ClarityAbiType, @@ -215,14 +213,6 @@ export class SegwitP2SHKeySigner extends CLITransactionSigner { } } -export class SafetyError extends Error { - safetyErrors: AnyJson; - constructor(safetyErrors: AnyJson) { - super(JSONStringify(safetyErrors, true)); - this.safetyErrors = safetyErrors; - } -} - function isCLITransactionSigner( signer: string | CLITransactionSigner ): signer is CLITransactionSigner { @@ -422,13 +412,6 @@ export function getPrivateKeyAddress( } } -/* - * Is a name a sponsored name (a subdomain)? - */ -export function isSubdomain(name: string): boolean { - return !!name.match(/^[^\.]+\.[^.]+\.[^.]+$/); -} - /* * Get the canonical form of a hex-encoded private key * (i.e. strip the trailing '01' if present) @@ -440,14 +423,6 @@ export function canonicalPrivateKey(privkey: string): string { return privkey; } -/* - * Get the sum of a set of UTXOs' values - * @txIn (object) the transaction - */ -export function sumUTXOs(utxos: UTXO[]): number { - return utxos.reduce((agg, x) => agg + x.value!, 0); -} - /* * Hash160 function for zone files */ @@ -455,23 +430,6 @@ export function hash160(buff: Buffer): Buffer { return bitcoinjs.crypto.hash160(buff); } -/* - * Normalize a URL--remove duplicate /'s from the root of the path. - * Throw an exception if it's not well-formed. - */ -export function checkUrl(url: string): string { - const urlinfo = URL.parse(url); - if (!urlinfo.protocol) { - throw new Error(`Malformed full URL: missing scheme in ${url}`); - } - - if (!urlinfo.path || urlinfo.path.startsWith('//')) { - throw new Error(`Malformed full URL: path root has multiple /'s: ${url}`); - } - - return url; -} - /* * Sign a profile into a JWT */ @@ -483,78 +441,6 @@ export function makeProfileJWT(profileData: Object, privateKey: string): string return JSONStringify(tokenRecords as unknown as AnyJson); } -export async function makeDIDConfiguration( - network: CLINetworkAdapter, - blockstackID: string, - domain: string, - privateKey: string -): Promise<{ entries: { did: string; jwt: string }[] }> { - const tokenSigner = new TokenSigner('ES256K', privateKey); - const nameInfo = await network.getNameInfo(blockstackID); - const did = nameInfo.did!; - const payload = { - iss: did, - domain, - exp: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), - }; - - const jwt = tokenSigner.sign(payload as any); - return { - entries: [ - { - did, - jwt, - }, - ], - }; -} -/* - * Broadcast a transaction and a zone file. - * Returns an object that encodes the success/failure of doing so. - * If zonefile is None, then only the transaction will be sent. - */ -export async function broadcastTransactionAndZoneFile( - network: CLINetworkAdapter, - tx: string, - zonefile?: string -) { - let txid: string; - return Promise.resolve() - .then(() => { - return network.broadcastTransaction(tx); - }) - .then((_txid: string) => { - txid = _txid; - if (zonefile) { - return network.broadcastZoneFile(zonefile, txid); - } else { - return { status: true }; - } - }) - .then(resp => { - if (!resp.status) { - return { - status: false, - error: 'Failed to broadcast zone file', - txid: txid, - }; - } else { - return { - status: true, - txid: txid, - }; - } - }) - .catch(e => { - return { - status: false, - error: 'Caught exception sending transaction or zone file', - message: e.message, - stacktrace: e.stack, - }; - }); -} - /* * Easier-to-use getNameInfo. Returns null if the name does not exist. */ diff --git a/packages/keychain/src/utils/gaia.ts b/packages/keychain/src/utils/gaia.ts index e3ebb1f1..830cfade 100644 --- a/packages/keychain/src/utils/gaia.ts +++ b/packages/keychain/src/utils/gaia.ts @@ -18,11 +18,6 @@ export const getHubInfo = async (hubUrl: string) => { return data; }; -export const getHubPrefix = async (hubUrl: string) => { - const { read_url_prefix } = await getHubInfo(hubUrl); - return read_url_prefix; -}; - export const makeGaiaAssociationToken = ( secretKeyHex: string, childPublicKeyHex: string diff --git a/packages/transactions/src/errors.ts b/packages/transactions/src/errors.ts index 170b57ec..4a901b43 100644 --- a/packages/transactions/src/errors.ts +++ b/packages/transactions/src/errors.ts @@ -1,14 +1,3 @@ -export class StacksTransactionError extends Error { - constructor(message: string) { - super(message); - this.message = message; - this.name = this.constructor.name; - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } - } -} - export class SerializationError extends Error { constructor(message: string) { super(message); diff --git a/packages/wallet-sdk/src/models/profile.ts b/packages/wallet-sdk/src/models/profile.ts index 9e9123ec..f8944694 100644 --- a/packages/wallet-sdk/src/models/profile.ts +++ b/packages/wallet-sdk/src/models/profile.ts @@ -39,17 +39,6 @@ export const DEFAULT_PROFILE: Profile = { export const DEFAULT_PROFILE_FILE_NAME = 'profile.json'; -export const fetchAccountProfile = async ({ - account, - gaiaHubUrl, -}: { - account: Account; - gaiaHubUrl: string; -}) => { - const url = await fetchAccountProfileUrl({ gaiaHubUrl, account }); - return fetchProfileFromUrl(url); -}; - export const fetchProfileFromUrl = async (profileUrl: string) => { try { const res = await fetchPrivate(profileUrl); diff --git a/packages/wallet-sdk/src/utils.ts b/packages/wallet-sdk/src/utils.ts index a1f84796..4daad9c8 100644 --- a/packages/wallet-sdk/src/utils.ts +++ b/packages/wallet-sdk/src/utils.ts @@ -44,11 +44,6 @@ export const getHubInfo = async (gaiaHubUrl: string) => { return data; }; -export const getHubPrefix = async (gaiaHubUrl: string) => { - const { read_url_prefix } = await getHubInfo(gaiaHubUrl); - return read_url_prefix; -}; - const makeGaiaAuthToken = ({ hubInfo, privateKey, @@ -129,25 +124,3 @@ export const makeGaiaAssociationToken = ({ const token = tokenSigner.sign(payload); return token; }; - -/** - * When you already know the Gaia read URL, make a Gaia config that doesn't have to fetch `/hub_info` - */ -export const convertGaiaHubConfig = ({ - gaiaHubConfig, - privateKey, -}: { - gaiaHubConfig: GaiaHubConfig; - privateKey: string; -}): GaiaHubConfig => { - const address = ecPairToAddress( - hexStringToECPair(privateKey + (privateKey.length === 64 ? '01' : '')) - ); - return { - url_prefix: gaiaHubConfig.url_prefix, - max_file_upload_size_megabytes: 100, - address, - token: 'not_used', - server: 'not_used', - }; -};