Skip to content

Commit

Permalink
fix: update cli
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Apr 24, 2024
1 parent cee19a2 commit 01c4f58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
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

0 comments on commit 01c4f58

Please sign in to comment.