Skip to content

Commit

Permalink
refactor: Rename make methods
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Oct 25, 2024
1 parent c6e982a commit ca875a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ This likely was a misunderstood and unused feature.

### Advanced: Refactorings

- The `StacksTransaction` was renamed to `StacksTransactionWire` and its class constructor was updated to take in an options object instead of individual parameters. In the future a new `StacksTransaction` may be introduced to replace it, with more human-readable properties.
- `postConditionMode` now also accepts string literals: `'deny'`, `'allow'` (in addition to the imported `PostConditionMode` enum).
- `anchorMode` and related items were deprecated, since they no longer change behavior on-chain.
- `pubKeyfromPrivKey` was renamed `privateKeyToPublic`
- `encodeStructuredData` now returns a hex-encoded string instead of a Uint8Array (use `encodeStructuredDataBytes` if you need the raw bytes).
- `decodeStructuredDataSignature` now returns a hex-encoded string instead of a Uint8Array (use `decodeStructuredDataSignatureBytes` if you need the raw bytes). Also fixes a bug that previously tried to parse input strings as UTF-8 bytes instead of hex-encoded strings.
- `hashStructuredData` now returns a hex-encoded string instead of a Uint8Array (use `hashStructuredDataBytes` if you need the raw bytes).
Expand All @@ -327,6 +331,10 @@ This likely was a misunderstood and unused feature.
- `generateSecretKey` was renamed to `randomSeedPhrase`.
- `nextYear`, `nextMonth`, `nextHour`, `makeUUID4`, `updateQueryStringParameter`, `getAesCbcOutputLength`, `getAPIUsageErrorMessage`, `isSameOriginAbsoluteUrl`, `isLaterVersion`, `getBase64OutputLength`, were marked as deprecated.
- `encrypt` and `decrypt` in `@stacks/wallet-sdk` (aliases of `encryptMnemonic` and `decryptMnemonic` in the `@stacks/encryption` package respectively) were removed.
- `makeECPrivateKey` in `@stacks/encryption` was deprecated, use `randomPrivateKey` instead.
- `makeSigHashPreSign` was renamed to `sigHashPreSign` and marked as internal.
- `makeSigHashPostSign` was renamed to `sigHashPostSign` and marked as internal.
- `@stacks/wallet-sdk` `WalletConfig` types and helpers were marked as deprecated.

## Stacks.js (<=4.x.x) → (5.x.x)

Expand Down
1 change: 1 addition & 0 deletions packages/encryption/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ utils.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {

/**
* @ignore
* @deprecated Use `randomPrivateKey` instead.
*/
export function makeECPrivateKey() {
return bytesToHex(utils.randomPrivateKey());
Expand Down
17 changes: 9 additions & 8 deletions packages/transactions/src/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ export function deserializeSpendingCondition(bytesReader: BytesReader): Spending
}
}

export function makeSigHashPreSign(
/** @ignore */
export function sigHashPreSign(
curSigHash: string,
authType: AuthType,
fee: IntegerType,
Expand Down Expand Up @@ -367,7 +368,7 @@ export function makeSigHashPreSign(
}

/** @internal */
function makeSigHashPostSign(curSigHash: string, pubKey: PublicKeyWire, signature: string): string {
function sigHashPostSign(curSigHash: string, pubKey: PublicKeyWire, signature: string): string {
// new hash combines the previous hash and all the new data this signature will add. This
// includes:
// * the public key compression flag
Expand Down Expand Up @@ -398,11 +399,11 @@ export function nextSignature(
nextSig: string;
nextSigHash: string;
} {
const sigHashPreSign = makeSigHashPreSign(curSigHash, authType, fee, nonce);
const sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);

const signature = signWithKey(privateKey, sigHashPreSign);
const signature = signWithKey(privateKey, sigHashPre);
const publicKey = createStacksPublicKey(privateKeyToPublic(privateKey));
const nextSigHash = makeSigHashPostSign(sigHashPreSign, publicKey, signature);
const nextSigHash = sigHashPostSign(sigHashPre, publicKey, signature);

return {
nextSig: signature,
Expand All @@ -418,13 +419,13 @@ export function nextVerification(
pubKeyEncoding: PubKeyEncoding,
signature: string
) {
const sigHashPreSign = makeSigHashPreSign(initialSigHash, authType, fee, nonce);
const sigHashPre = sigHashPreSign(initialSigHash, authType, fee, nonce);

const publicKey = createStacksPublicKey(
publicKeyFromSignatureVrs(sigHashPreSign, signature, pubKeyEncoding)
publicKeyFromSignatureVrs(sigHashPre, signature, pubKeyEncoding)
);

const nextSigHash = makeSigHashPostSign(sigHashPreSign, publicKey, signature);
const nextSigHash = sigHashPostSign(sigHashPre, publicKey, signature);

return {
pubKey: publicKey,
Expand Down

0 comments on commit ca875a7

Please sign in to comment.