Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update cli #1656

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
ClarityValue,
ContractCallPayload,
SignedContractDeployOptions,
createStacksPrivateKey,
cvToString,
estimateTransfer,
getAbi,
Expand All @@ -28,8 +27,6 @@ import {
makeContractDeploy,
makeSTXTokenTransfer,
PostConditionMode,
pubKeyfromPrivKey,
publicKeyToString,
ReadOnlyFunctionOptions,
SignedContractCallOptions,
SignedTokenTransferOptions,
Expand All @@ -44,6 +41,7 @@ import {
estimateTransaction,
serializePayload,
estimateTransactionByteLength,
privateKeyToPublic,
} from '@stacks/transactions';
import express from 'express';
import { prompt } from 'inquirer';
Expand Down Expand Up @@ -447,7 +445,7 @@ async function migrateSubdomains(network: CLINetworkAdapter, args: string[]): Pr
* ********************************************************************************
*/
const hash = crypto.createHash('sha256').update(textToSign).digest('hex');
const sig = signWithKey(createStacksPrivateKey(account.dataPrivateKey), hash);
const sig = signWithKey(account.dataPrivateKey, hash);

// https://docs.stacks.co/build-apps/references/bns#subdomain-lifecycle
subDomainOp.signature = sig.data;
Expand Down Expand Up @@ -1870,7 +1868,7 @@ async function register(network: CLINetworkAdapter, args: string[]): Promise<str
const privateKey = args[1];
const salt = args[2];
const zonefile = args[3];
const publicKey = publicKeyToString(pubKeyfromPrivKey(privateKey));
const publicKey = privateKeyToPublic(privateKey);

const api = new StacksNodeApi({ network: network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET });

Expand All @@ -1883,7 +1881,7 @@ async function register(network: CLINetworkAdapter, args: string[]): Promise<str
});

const signer = new TransactionSigner(unsignedTransaction);
signer.signOrigin(createStacksPrivateKey(privateKey));
signer.signOrigin(privateKey);

return broadcastTransaction({ transaction: signer.transaction, api })
.then((response: TxBroadcastResult) => {
Expand All @@ -1905,7 +1903,7 @@ async function preorder(network: CLINetworkAdapter, args: string[]): Promise<str
const privateKey = args[1];
const salt = args[2];
const stxToBurn = args[3];
const publicKey = publicKeyToString(pubKeyfromPrivKey(privateKey));
const publicKey = privateKeyToPublic(privateKey);

const api = new StacksNodeApi({ network: network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET });

Expand All @@ -1918,7 +1916,7 @@ async function preorder(network: CLINetworkAdapter, args: string[]): Promise<str
});

const signer = new TransactionSigner(unsignedTransaction);
signer.signOrigin(createStacksPrivateKey(privateKey));
signer.signOrigin(privateKey);

return broadcastTransaction({ transaction: signer.transaction, api })
.then((response: TxBroadcastResult) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { publicKeyToBtcAddress } from '@stacks/encryption';
import { pubKeyfromPrivKey } from '@stacks/transactions';
import * as bitcoinjs from 'bitcoinjs-lib';
import { TransactionSigner } from 'blockstack';
import { DEFAULT_MAX_ID_SEARCH_INDEX } from './argparse';
import { CLINetworkAdapter } from './network';
import { privateKeyToPublic } from '@stacks/transactions/src';

let maxIDSearchIndex = DEFAULT_MAX_ID_SEARCH_INDEX;

Expand Down Expand Up @@ -49,8 +49,8 @@ export function getPrivateKeyAddress(
return privateKey.address;
}

const pubKey = pubKeyfromPrivKey(privateKey);
const btcAddress = publicKeyToBtcAddress(pubKey.data);
const pubKey = privateKeyToPublic(privateKey);
const btcAddress = publicKeyToBtcAddress(pubKey);
return network.coerceAddress(btcAddress);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CLINetworkAdapter, CLI_NETWORK_OPTS, getNetwork } from '../src/network'
import {
Cl,
ClarityAbi,
createStacksPrivateKey,
publicKeyFromSignatureVrs,
randomBytes,
signWithKey,
Expand Down Expand Up @@ -417,7 +416,7 @@ describe('Subdomain Migration', () => {
* ********************************************************************************
*/
const hash = crypto.createHash('sha256').update(textToSign).digest('hex');
const sig = signWithKey(createStacksPrivateKey(privateKey), hash);
const sig = signWithKey(privateKey, hash);

subDomainOp.signature = sig.data; // Assign signature to subDomainOp

Expand Down
Loading