@stacks/stacking
Advanced tools
Comparing version 7.0.0-next.70 to 7.0.0-next.89
import { ClientOpts, IntegerType, PrivateKey } from '@stacks/common'; | ||
import { StacksNetwork, StacksNetworkName } from '@stacks/network'; | ||
import { NetworkClientParam, StacksNetwork } from '@stacks/network'; | ||
import { BurnchainRewardListResponse, BurnchainRewardSlotHolderListResponse, BurnchainRewardsTotal } from '@stacks/stacks-blockchain-api-types'; | ||
import type { ContractIdString } from '@stacks/transactions'; | ||
import { ContractCallOptions, StacksTransaction, TxBroadcastResult } from '@stacks/transactions'; | ||
import { ContractCallOptions, StacksTransactionWire, TxBroadcastResult } from '@stacks/transactions'; | ||
import { PoxOperationPeriod } from './constants'; | ||
@@ -182,5 +182,3 @@ import { Pox4SignatureTopic } from './utils'; | ||
address: string; | ||
network: StacksNetworkName | StacksNetwork; | ||
client?: ClientOpts; | ||
}); | ||
} & NetworkClientParam); | ||
get baseUrl(): string; | ||
@@ -315,6 +313,6 @@ get fetch(): import("@stacks/common").FetchFn; | ||
getStackingContract(poxOperationInfo?: PoxOperationInfo): Promise<string>; | ||
modifyLockTxFee({ tx, amountMicroStx }: { | ||
tx: StacksTransaction; | ||
modifyLockTxFee({ tx, amountMicroStx, }: { | ||
tx: StacksTransactionWire; | ||
amountMicroStx: IntegerType; | ||
}): StacksTransaction; | ||
}): StacksTransactionWire; | ||
parseContractId(contract: string): string[]; | ||
@@ -321,0 +319,0 @@ signPoxSignature({ topic, poxAddress, rewardCycle, period, signerPrivateKey, authId, maxAmount, }: { |
import { hexToBytes, intToBigInt } from '@stacks/common'; | ||
import { ChainId, defaultClientOptsFromNetwork, networkFrom, } from '@stacks/network'; | ||
import { ChainId, clientFromNetwork, networkFrom, } from '@stacks/network'; | ||
import { ClarityType, broadcastTransaction, bufferCV, cvToString, fetchCallReadOnlyFunction, getFee, makeContractCall, noneCV, principalCV, someCV, stringAsciiCV, uintCV, validateStacksAddress, } from '@stacks/transactions'; | ||
@@ -10,4 +10,4 @@ import { PoxOperationPeriod, StackingErrors } from './constants'; | ||
this.address = opts.address; | ||
this.network = networkFrom(opts.network); | ||
this.client = defaultClientOptsFromNetwork(this.network, opts.client); | ||
this.network = networkFrom(opts.network ?? 'mainnet'); | ||
this.client = Object.assign({}, clientFromNetwork(this.network), opts.client); | ||
} | ||
@@ -717,3 +717,3 @@ get baseUrl() { | ||
} | ||
modifyLockTxFee({ tx, amountMicroStx }) { | ||
modifyLockTxFee({ tx, amountMicroStx, }) { | ||
const fee = getFee(tx.auth); | ||
@@ -720,0 +720,0 @@ tx.payload.functionArgs[0] = uintCV(intToBigInt(amountMicroStx) - fee); |
@@ -12,2 +12,6 @@ import { IntegerType, PrivateKey } from '@stacks/common'; | ||
version: PoXAddressVersion; | ||
data: string; | ||
}; | ||
export declare function decodeBtcAddressBytes(btcAddress: string): { | ||
version: PoXAddressVersion; | ||
data: Uint8Array; | ||
@@ -21,3 +25,3 @@ }; | ||
export declare function poxAddressToTuple(poxAddress: string): TupleCV<import("@stacks/transactions").TupleData<BufferCV>>; | ||
export declare function poxAddressToBtcAddress(version: number, hashBytes: Uint8Array, network: StacksNetworkName): string; | ||
export declare function poxAddressToBtcAddress(version: number, hash: string | Uint8Array, network: StacksNetworkName): string; | ||
export declare function poxAddressToBtcAddress(poxAddrClarityValue: ClarityValue, network: StacksNetworkName): string; | ||
@@ -24,0 +28,0 @@ export declare function unwrap<T extends ClarityValue>(optional: OptionalCV<T>): T | undefined; |
import { sha256 } from '@noble/hashes/sha256'; | ||
import { bech32, bech32m } from '@scure/base'; | ||
import { bigIntToBytes, hexToBytes } from '@stacks/common'; | ||
import { bigIntToBytes, bytesToHex, hexToBytes } from '@stacks/common'; | ||
import { base58CheckDecode, base58CheckEncode, verifyMessageSignatureRsv, } from '@stacks/encryption'; | ||
import { StacksNetworks, networkFrom } from '@stacks/network'; | ||
import { ClarityType, bufferCV, encodeStructuredData, signStructuredData, stringAsciiCV, tupleCV, uintCV, } from '@stacks/transactions'; | ||
import { ClarityType, bufferCV, encodeStructuredDataBytes, signStructuredData, stringAsciiCV, tupleCV, uintCV, } from '@stacks/transactions'; | ||
import { B58_ADDR_PREFIXES, BitcoinNetworkVersion, PoXAddressVersion, PoxOperationPeriod, SEGWIT_ADDR_PREFIXES, SEGWIT_V0, SEGWIT_V0_ADDR_PREFIX, SEGWIT_V1, SEGWIT_V1_ADDR_PREFIX, SegwitPrefix, StackingErrors, } from './constants'; | ||
@@ -71,2 +71,6 @@ export class InvalidAddressError extends Error { | ||
export function decodeBtcAddress(btcAddress) { | ||
const { version, data } = decodeBtcAddressBytes(btcAddress); | ||
return { version, data: bytesToHex(data) }; | ||
} | ||
export function decodeBtcAddressBytes(btcAddress) { | ||
try { | ||
@@ -172,3 +176,3 @@ if (B58_ADDR_PREFIXES.test(btcAddress)) { | ||
export function poxAddressToTuple(poxAddress) { | ||
const { version, data } = decodeBtcAddress(poxAddress); | ||
const { version, data } = decodeBtcAddressBytes(poxAddress); | ||
const versionBuff = bufferCV(bigIntToBytes(BigInt(version), 1)); | ||
@@ -193,5 +197,7 @@ const hashBuff = bufferCV(data); | ||
} | ||
function _poxAddressToBtcAddress_Values(version, hashBytes, network) { | ||
function _poxAddressToBtcAddress_Values(version, hash, network) { | ||
if (!StacksNetworks.includes(network)) | ||
throw new Error('Invalid network.'); | ||
if (typeof hash === 'string') | ||
hash = hexToBytes(hash); | ||
switch (version) { | ||
@@ -203,11 +209,11 @@ case PoXAddressVersion.P2PKH: | ||
const btcAddrVersion = legacyHashModeToBtcAddressVersion(version, network); | ||
return base58CheckEncode(btcAddrVersion, hashBytes); | ||
return base58CheckEncode(btcAddrVersion, hash); | ||
} | ||
case PoXAddressVersion.P2WPKH: | ||
case PoXAddressVersion.P2WSH: { | ||
const words = bech32.toWords(hashBytes); | ||
const words = bech32.toWords(hash); | ||
return bech32.encode(SegwitPrefix[network], [SEGWIT_V0, ...words]); | ||
} | ||
case PoXAddressVersion.P2TR: { | ||
const words = bech32m.toWords(hashBytes); | ||
const words = bech32m.toWords(hash); | ||
return bech32m.encode(SegwitPrefix[network], [SEGWIT_V1, ...words]); | ||
@@ -282,3 +288,3 @@ } | ||
return verifyMessageSignatureRsv({ | ||
message: sha256(encodeStructuredData(pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }))), | ||
message: sha256(encodeStructuredDataBytes(pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }))), | ||
publicKey, | ||
@@ -285,0 +291,0 @@ signature, |
import { ClientOpts, IntegerType, PrivateKey } from '@stacks/common'; | ||
import { StacksNetwork, StacksNetworkName } from '@stacks/network'; | ||
import { NetworkClientParam, StacksNetwork } from '@stacks/network'; | ||
import { BurnchainRewardListResponse, BurnchainRewardSlotHolderListResponse, BurnchainRewardsTotal } from '@stacks/stacks-blockchain-api-types'; | ||
import type { ContractIdString } from '@stacks/transactions'; | ||
import { ContractCallOptions, StacksTransaction, TxBroadcastResult } from '@stacks/transactions'; | ||
import { ContractCallOptions, StacksTransactionWire, TxBroadcastResult } from '@stacks/transactions'; | ||
import { PoxOperationPeriod } from './constants'; | ||
@@ -182,5 +182,3 @@ import { Pox4SignatureTopic } from './utils'; | ||
address: string; | ||
network: StacksNetworkName | StacksNetwork; | ||
client?: ClientOpts; | ||
}); | ||
} & NetworkClientParam); | ||
get baseUrl(): string; | ||
@@ -315,6 +313,6 @@ get fetch(): import("@stacks/common").FetchFn; | ||
getStackingContract(poxOperationInfo?: PoxOperationInfo): Promise<string>; | ||
modifyLockTxFee({ tx, amountMicroStx }: { | ||
tx: StacksTransaction; | ||
modifyLockTxFee({ tx, amountMicroStx, }: { | ||
tx: StacksTransactionWire; | ||
amountMicroStx: IntegerType; | ||
}): StacksTransaction; | ||
}): StacksTransactionWire; | ||
parseContractId(contract: string): string[]; | ||
@@ -321,0 +319,0 @@ signPoxSignature({ topic, poxAddress, rewardCycle, period, signerPrivateKey, authId, maxAmount, }: { |
@@ -27,4 +27,4 @@ "use strict"; | ||
this.address = opts.address; | ||
this.network = (0, network_1.networkFrom)(opts.network); | ||
this.client = (0, network_1.defaultClientOptsFromNetwork)(this.network, opts.client); | ||
this.network = (0, network_1.networkFrom)(opts.network ?? 'mainnet'); | ||
this.client = Object.assign({}, (0, network_1.clientFromNetwork)(this.network), opts.client); | ||
} | ||
@@ -734,3 +734,3 @@ get baseUrl() { | ||
} | ||
modifyLockTxFee({ tx, amountMicroStx }) { | ||
modifyLockTxFee({ tx, amountMicroStx, }) { | ||
const fee = (0, transactions_1.getFee)(tx.auth); | ||
@@ -737,0 +737,0 @@ tx.payload.functionArgs[0] = (0, transactions_1.uintCV)((0, common_1.intToBigInt)(amountMicroStx) - fee); |
@@ -12,2 +12,6 @@ import { IntegerType, PrivateKey } from '@stacks/common'; | ||
version: PoXAddressVersion; | ||
data: string; | ||
}; | ||
export declare function decodeBtcAddressBytes(btcAddress: string): { | ||
version: PoXAddressVersion; | ||
data: Uint8Array; | ||
@@ -21,3 +25,3 @@ }; | ||
export declare function poxAddressToTuple(poxAddress: string): TupleCV<import("@stacks/transactions").TupleData<BufferCV>>; | ||
export declare function poxAddressToBtcAddress(version: number, hashBytes: Uint8Array, network: StacksNetworkName): string; | ||
export declare function poxAddressToBtcAddress(version: number, hash: string | Uint8Array, network: StacksNetworkName): string; | ||
export declare function poxAddressToBtcAddress(poxAddrClarityValue: ClarityValue, network: StacksNetworkName): string; | ||
@@ -24,0 +28,0 @@ export declare function unwrap<T extends ClarityValue>(optional: OptionalCV<T>): T | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pox4SignatureMessage = exports.verifyPox4SignatureHash = exports.signPox4SignatureHash = exports.Pox4SignatureTopic = exports.ensureSignerArgsReadiness = exports.ensureLegacyBtcAddressForPox1 = exports.ensurePox2Activated = exports.unwrapMap = exports.unwrap = exports.poxAddressToBtcAddress = exports.poxAddressToTuple = exports.getErrorString = exports.extractPoxAddressFromClarityValue = exports.decodeBtcAddress = exports.btcAddressVersionToLegacyHashMode = exports.InvalidAddressError = void 0; | ||
exports.pox4SignatureMessage = exports.verifyPox4SignatureHash = exports.signPox4SignatureHash = exports.Pox4SignatureTopic = exports.ensureSignerArgsReadiness = exports.ensureLegacyBtcAddressForPox1 = exports.ensurePox2Activated = exports.unwrapMap = exports.unwrap = exports.poxAddressToBtcAddress = exports.poxAddressToTuple = exports.getErrorString = exports.extractPoxAddressFromClarityValue = exports.decodeBtcAddressBytes = exports.decodeBtcAddress = exports.btcAddressVersionToLegacyHashMode = exports.InvalidAddressError = void 0; | ||
const sha256_1 = require("@noble/hashes/sha256"); | ||
@@ -76,2 +76,7 @@ const base_1 = require("@scure/base"); | ||
function decodeBtcAddress(btcAddress) { | ||
const { version, data } = decodeBtcAddressBytes(btcAddress); | ||
return { version, data: (0, common_1.bytesToHex)(data) }; | ||
} | ||
exports.decodeBtcAddress = decodeBtcAddress; | ||
function decodeBtcAddressBytes(btcAddress) { | ||
try { | ||
@@ -100,3 +105,3 @@ if (constants_1.B58_ADDR_PREFIXES.test(btcAddress)) { | ||
} | ||
exports.decodeBtcAddress = decodeBtcAddress; | ||
exports.decodeBtcAddressBytes = decodeBtcAddressBytes; | ||
function extractPoxAddressFromClarityValue(poxAddrClarityValue) { | ||
@@ -181,3 +186,3 @@ const clarityValue = poxAddrClarityValue; | ||
function poxAddressToTuple(poxAddress) { | ||
const { version, data } = decodeBtcAddress(poxAddress); | ||
const { version, data } = decodeBtcAddressBytes(poxAddress); | ||
const versionBuff = (0, transactions_1.bufferCV)((0, common_1.bigIntToBytes)(BigInt(version), 1)); | ||
@@ -203,5 +208,7 @@ const hashBuff = (0, transactions_1.bufferCV)(data); | ||
} | ||
function _poxAddressToBtcAddress_Values(version, hashBytes, network) { | ||
function _poxAddressToBtcAddress_Values(version, hash, network) { | ||
if (!network_1.StacksNetworks.includes(network)) | ||
throw new Error('Invalid network.'); | ||
if (typeof hash === 'string') | ||
hash = (0, common_1.hexToBytes)(hash); | ||
switch (version) { | ||
@@ -213,11 +220,11 @@ case constants_1.PoXAddressVersion.P2PKH: | ||
const btcAddrVersion = legacyHashModeToBtcAddressVersion(version, network); | ||
return (0, encryption_1.base58CheckEncode)(btcAddrVersion, hashBytes); | ||
return (0, encryption_1.base58CheckEncode)(btcAddrVersion, hash); | ||
} | ||
case constants_1.PoXAddressVersion.P2WPKH: | ||
case constants_1.PoXAddressVersion.P2WSH: { | ||
const words = base_1.bech32.toWords(hashBytes); | ||
const words = base_1.bech32.toWords(hash); | ||
return base_1.bech32.encode(constants_1.SegwitPrefix[network], [constants_1.SEGWIT_V0, ...words]); | ||
} | ||
case constants_1.PoXAddressVersion.P2TR: { | ||
const words = base_1.bech32m.toWords(hashBytes); | ||
const words = base_1.bech32m.toWords(hash); | ||
return base_1.bech32m.encode(constants_1.SegwitPrefix[network], [constants_1.SEGWIT_V1, ...words]); | ||
@@ -299,3 +306,3 @@ } | ||
return (0, encryption_1.verifyMessageSignatureRsv)({ | ||
message: (0, sha256_1.sha256)((0, transactions_1.encodeStructuredData)(pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }))), | ||
message: (0, sha256_1.sha256)((0, transactions_1.encodeStructuredDataBytes)(pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }))), | ||
publicKey, | ||
@@ -302,0 +309,0 @@ signature, |
{ | ||
"name": "@stacks/stacking", | ||
"version": "7.0.0-next.70+0adf46c4", | ||
"version": "7.0.0-next.89+3d4052b2", | ||
"description": "Library for Stacking.", | ||
@@ -25,7 +25,7 @@ "license": "MIT", | ||
"@scure/base": "1.1.1", | ||
"@stacks/common": "^7.0.0-next.70+0adf46c4", | ||
"@stacks/encryption": "^7.0.0-next.70+0adf46c4", | ||
"@stacks/network": "^7.0.0-next.70+0adf46c4", | ||
"@stacks/common": "^7.0.0-next.89+3d4052b2", | ||
"@stacks/encryption": "^7.0.0-next.89+3d4052b2", | ||
"@stacks/network": "^7.0.0-next.89+3d4052b2", | ||
"@stacks/stacks-blockchain-api-types": "^0.61.0", | ||
"@stacks/transactions": "^7.0.0-next.70+0adf46c4", | ||
"@stacks/transactions": "^7.0.0-next.89+3d4052b2", | ||
"bs58": "^5.0.0" | ||
@@ -62,3 +62,3 @@ }, | ||
}, | ||
"gitHead": "0adf46c4eadac85f234140dc2df0e5d06b0ca775" | ||
"gitHead": "3d4052b21c76cd8f28ae64a266d61b650386a726" | ||
} |
import { ClientOpts, IntegerType, PrivateKey, hexToBytes, intToBigInt } from '@stacks/common'; | ||
import { | ||
ChainId, | ||
NetworkClientParam, | ||
StacksNetwork, | ||
StacksNetworkName, | ||
defaultClientOptsFromNetwork, | ||
clientFromNetwork, | ||
networkFrom, | ||
@@ -24,3 +24,3 @@ } from '@stacks/network'; | ||
ResponseErrorCV, | ||
StacksTransaction, | ||
StacksTransactionWire, | ||
TupleCV, | ||
@@ -338,10 +338,6 @@ TxBroadcastResult, | ||
// todo: make more constructor opts optional | ||
constructor(opts: { | ||
address: string; | ||
network: StacksNetworkName | StacksNetwork; | ||
client?: ClientOpts; | ||
}) { | ||
constructor(opts: { address: string } & NetworkClientParam) { | ||
this.address = opts.address; | ||
this.network = networkFrom(opts.network); | ||
this.client = defaultClientOptsFromNetwork(this.network, opts.client); | ||
this.network = networkFrom(opts.network ?? 'mainnet'); | ||
this.client = Object.assign({}, clientFromNetwork(this.network), opts.client); | ||
} | ||
@@ -1578,5 +1574,11 @@ | ||
* | ||
* @returns {StacksTransaction} that resolves to a transaction object if the operation succeeds | ||
* @returns {StacksTransactionWire} that resolves to a transaction object if the operation succeeds | ||
*/ | ||
modifyLockTxFee({ tx, amountMicroStx }: { tx: StacksTransaction; amountMicroStx: IntegerType }) { | ||
modifyLockTxFee({ | ||
tx, | ||
amountMicroStx, | ||
}: { | ||
tx: StacksTransactionWire; | ||
amountMicroStx: IntegerType; | ||
}) { | ||
const fee = getFee(tx.auth); | ||
@@ -1583,0 +1585,0 @@ (tx.payload as ContractCallPayload).functionArgs[0] = uintCV(intToBigInt(amountMicroStx) - fee); |
import { sha256 } from '@noble/hashes/sha256'; | ||
import { bech32, bech32m } from '@scure/base'; | ||
import { IntegerType, PrivateKey, bigIntToBytes, hexToBytes } from '@stacks/common'; | ||
import { IntegerType, PrivateKey, bigIntToBytes, bytesToHex, hexToBytes } from '@stacks/common'; | ||
import { | ||
@@ -17,3 +17,3 @@ base58CheckDecode, | ||
bufferCV, | ||
encodeStructuredData, | ||
encodeStructuredDataBytes, | ||
signStructuredData, | ||
@@ -83,2 +83,3 @@ stringAsciiCV, | ||
/** @ignore */ | ||
function bech32Decode(btcAddress: string) { | ||
@@ -97,2 +98,3 @@ const { words: bech32Words } = bech32.decode(btcAddress); | ||
/** @ignore */ | ||
function bech32MDecode(btcAddress: string) { | ||
@@ -111,2 +113,3 @@ const { words: bech32MWords } = bech32m.decode(btcAddress); | ||
/** @ignore */ | ||
function decodeNativeSegwitBtcAddress(btcAddress: string): { | ||
@@ -125,2 +128,10 @@ witnessVersion: number; | ||
version: PoXAddressVersion; | ||
data: string; | ||
} { | ||
const { version, data } = decodeBtcAddressBytes(btcAddress); | ||
return { version, data: bytesToHex(data) }; | ||
} | ||
export function decodeBtcAddressBytes(btcAddress: string): { | ||
version: PoXAddressVersion; | ||
data: Uint8Array; | ||
@@ -241,3 +252,3 @@ } { | ||
export function poxAddressToTuple(poxAddress: string) { | ||
const { version, data } = decodeBtcAddress(poxAddress); | ||
const { version, data } = decodeBtcAddressBytes(poxAddress); | ||
const versionBuff = bufferCV(bigIntToBytes(BigInt(version), 1)); | ||
@@ -270,3 +281,3 @@ const hashBuff = bufferCV(data); | ||
version: number, | ||
hashBytes: Uint8Array, | ||
hash: string | Uint8Array, | ||
network: StacksNetworkName | ||
@@ -276,2 +287,4 @@ ): string { | ||
if (typeof hash === 'string') hash = hexToBytes(hash); | ||
switch (version) { | ||
@@ -283,11 +296,11 @@ case PoXAddressVersion.P2PKH: | ||
const btcAddrVersion = legacyHashModeToBtcAddressVersion(version, network); | ||
return base58CheckEncode(btcAddrVersion, hashBytes); | ||
return base58CheckEncode(btcAddrVersion, hash); | ||
} | ||
case PoXAddressVersion.P2WPKH: | ||
case PoXAddressVersion.P2WSH: { | ||
const words = bech32.toWords(hashBytes); | ||
const words = bech32.toWords(hash); | ||
return bech32.encode(SegwitPrefix[network], [SEGWIT_V0, ...words]); | ||
} | ||
case PoXAddressVersion.P2TR: { | ||
const words = bech32m.toWords(hashBytes); | ||
const words = bech32m.toWords(hash); | ||
return bech32m.encode(SegwitPrefix[network], [SEGWIT_V1, ...words]); | ||
@@ -311,3 +324,3 @@ } | ||
* @param version - The version of the PoX address (as a single number, not a Uint8array). | ||
* @param hashBytes - The hash bytes of the PoX address. | ||
* @param hash - The hash bytes of the PoX address. | ||
* @param network - The network the PoX address is on. | ||
@@ -318,4 +331,4 @@ * @returns The corresponding Bitcoin address. | ||
version: number, | ||
hashBytes: Uint8Array, | ||
network: StacksNetworkName | ||
hash: string | Uint8Array, | ||
network: StacksNetworkName // todo: allow NetworkParam in the future (minor) | ||
): string; | ||
@@ -472,3 +485,3 @@ /** | ||
message: sha256( | ||
encodeStructuredData( | ||
encodeStructuredDataBytes( | ||
pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }) | ||
@@ -475,0 +488,0 @@ ) |
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
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
1119556
6090