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 22, 2024
1 parent e78cc74 commit 5172bce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ 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.

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

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

/**
* @ignore
* @deprecated Use `randomPrivateKey` instead.
*/
export function makeECPrivateKey() {
return bytesToHex(utils.randomPrivateKey());
}

/** Generate a random elliptic-curve private key */
export function randomPrivateKey() {
return bytesToHex(utils.randomPrivateKey());
}

/**
* Based on bitcoinjs-lib MIT https://github.com/bitcoinjs/bs58check/blob/12b3e700f355c5c49d0be3f8fc29be6c66e753e9/base.js
* @ignore
Expand Down
15 changes: 8 additions & 7 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 @@ -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 = makeSigHashPostSign(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 = makeSigHashPostSign(sigHashPre, publicKey, signature);

return {
pubKey: publicKey,
Expand Down

0 comments on commit 5172bce

Please sign in to comment.