From f1e866fb751fdcc38658a209e63c0b56ea099e20 Mon Sep 17 00:00:00 2001 From: janniks Date: Wed, 31 Jul 2024 23:46:43 +0200 Subject: [PATCH] refactor!: Remove wrapper type for message signatures --- .github/MIGRATION.md | 11 ++++ packages/bns/src/index.ts | 8 +-- packages/cli/package.json | 4 +- packages/cli/src/cli.ts | 2 +- packages/cli/tests/cli.test.ts | 2 +- packages/stacking/src/utils.ts | 2 +- packages/transactions/src/authorization.ts | 20 ++++--- packages/transactions/src/builders.ts | 54 ++++++++++--------- packages/transactions/src/keys.ts | 31 ++++------- packages/transactions/src/signer.ts | 2 +- .../src/structuredDataSignature.ts | 12 ++--- packages/transactions/src/transaction.ts | 5 +- .../transactions/tests/authorization.test.ts | 2 +- packages/transactions/tests/builder.test.ts | 10 ++-- packages/transactions/tests/keys.test.ts | 6 +-- .../tests/structuredDataSignature.test.ts | 8 +-- 16 files changed, 89 insertions(+), 90 deletions(-) diff --git a/.github/MIGRATION.md b/.github/MIGRATION.md index b3e3cd342..8bdcbd15d 100644 --- a/.github/MIGRATION.md +++ b/.github/MIGRATION.md @@ -5,6 +5,7 @@ - [Stacks Network](#stacks-network) - [Impacts](#impacts) - [Fetch Methods](#fetch-methods) + - [Reducing Wrapper Types](#reducing-wrapper-types) - [StacksNodeApi](#stacksnodeapi) - [StacksNetwork to StacksNodeApi](#stacksnetwork-to-stacksnodeapi) - [Clarity Representation](#clarity-representation) @@ -36,6 +37,7 @@ - The `@stacks/network` `new StacksNetwork()` objects were removed. Instead `@stacks/network` now exports the objects `STACKS_MAINNET`, `STACKS_TESNET`, and `STACKS_DEVNET`, which are static (and shouldn't be changed for most use-cases). [Read more...](#stacks-network) - Most `fetch` (aka networking) methods were renamed to indicate they send HTTP requests. The new methods are named `fetchXyz` and are compatible with the old `Xyz` interfaces. [Read more...](#fetch-methods) +- Reducing wrapper types, which create annoyances for the developer, rather than being able to use values directly. [Read more...](#reducing-wrapper-types) - The `ClarityType` enum was replaced by a human-readable version. The previous (wire format compatible) enum is still available as `ClarityWireType`. [Read more...](#clarity-representation) - The previous post-conditions types and `create..` methods were replaced with a human-readable representation. [Read more...](#post-conditions) - `StacksTransaction.serialize` and other `serializeXyz` methods were changed to return `string` (hex-encoded) instead of `Uint8Array`. Compatible `serializeXzyBytes` methods were added to ease the migration. [Read more...](#serialize-methods) @@ -83,6 +85,15 @@ The following methods were renamed: `broadcastTransaction` wasn't renamed to highlight the uniqueness of the method. Namely, the node/API it is sent to will "broadcast" the transaction to the mempool. +### Reducing Wrapper Types + +With this release we are aiming to reduce unnecessary "wrapper" types, which are used in the internals of the codebase, but shouldn't be pushed onto the user/developer. + +This breaks the signatures of many functions: + +- `signMessageHashRsv`, `signWithKey` now return the message signature as a `string` directly. +- `nextSignature`, `nextVerification`, `publicKeyFromSignatureVrs`, `publicKeyFromSignatureRsv` now take in the message signature as a `string`. + ### StacksNodeApi The new `StacksNodeApi` class lets you interact with a Stacks node or API. diff --git a/packages/bns/src/index.ts b/packages/bns/src/index.ts index 54dd4335a..4ba563b2c 100644 --- a/packages/bns/src/index.ts +++ b/packages/bns/src/index.ts @@ -1,4 +1,4 @@ -import { ApiParam, IntegerType, intToBigInt, utf8ToBytes } from '@stacks/common'; +import { ApiParam, IntegerType, PublicKey, intToBigInt, utf8ToBytes } from '@stacks/common'; import { StacksNetwork } from '@stacks/network'; import { ClarityType, @@ -55,7 +55,7 @@ export interface PriceFunction { export interface BnsContractCallOptions { functionName: string; functionArgs: ClarityValue[]; - publicKey: string; + publicKey: PublicKey; network: StacksNetwork; postConditions?: PostCondition[]; } @@ -480,7 +480,7 @@ export interface PreorderNameOptions { /** amount of STX to burn for the registration */ stxToBurn: IntegerType; /** the private key to sign the transaction */ - publicKey: string; + publicKey: PublicKey; /** the Stacks blockchain network to use */ network: StacksNetwork; } @@ -541,7 +541,7 @@ export interface RegisterNameOptions { fullyQualifiedName: string; salt: string; zonefile: string; - publicKey: string; + publicKey: PublicKey; network: StacksNetwork; } diff --git a/packages/cli/package.json b/packages/cli/package.json index d30e9969f..d9b14e812 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -15,7 +15,9 @@ "prepublishOnly": "npm run test && NODE_ENV=production npm run build", "start": "tsc -b tsconfig.build.json --watch --verbose", "test": "jest", - "test:watch": "jest --watch --coverage=false" + "test:watch": "jest --watch --coverage=false", + "typecheck": "tsc --noEmit", + "typecheck:watch": "npm run typecheck -- --watch" }, "dependencies": { "@scure/bip32": "1.1.3", diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 512547deb..4d32a09a7 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -435,7 +435,7 @@ async function migrateSubdomains(network: CLINetworkAdapter, args: string[]): Pr const sig = signWithKey(account.dataPrivateKey, hash); // https://docs.stacks.co/build-apps/references/bns#subdomain-lifecycle - subDomainOp.signature = sig.data; + subDomainOp.signature = sig; payload.subdomains_list.push(subDomainOp); } diff --git a/packages/cli/tests/cli.test.ts b/packages/cli/tests/cli.test.ts index 911438344..b65b981fb 100644 --- a/packages/cli/tests/cli.test.ts +++ b/packages/cli/tests/cli.test.ts @@ -420,7 +420,7 @@ describe('Subdomain Migration', () => { const hash = crypto.createHash('sha256').update(textToSign).digest('hex'); const sig = signWithKey(privateKey, hash); - subDomainOp.signature = sig.data; // Assign signature to subDomainOp + subDomainOp.signature = sig; // Assign signature to subDomainOp // Verify that the generated signature is valid const pubKey = publicKeyFromSignatureVrs(hash, sig); diff --git a/packages/stacking/src/utils.ts b/packages/stacking/src/utils.ts index f8466f485..906495843 100644 --- a/packages/stacking/src/utils.ts +++ b/packages/stacking/src/utils.ts @@ -438,7 +438,7 @@ export function signPox4SignatureHash({ return signStructuredData({ ...pox4SignatureMessage({ topic, poxAddress, rewardCycle, period, network, maxAmount, authId }), privateKey, - }).data; + }); } /** diff --git a/packages/transactions/src/authorization.ts b/packages/transactions/src/authorization.ts index 90fa38416..b6112f8c7 100644 --- a/packages/transactions/src/authorization.ts +++ b/packages/transactions/src/authorization.ts @@ -6,6 +6,7 @@ import { intToBigInt, intToBytes, PrivateKey, + PublicKey, writeUInt16BE, } from '@stacks/common'; import { BytesReader } from './BytesReader'; @@ -117,7 +118,7 @@ export function createSpendingCondition( export function createSingleSigSpendingCondition( hashMode: SingleSigHashMode, - pubKey: string, + pubKey: PublicKey, nonce: IntegerType, fee: IntegerType ): SingleSigSpendingCondition { @@ -365,11 +366,8 @@ export function makeSigHashPreSign( return txidFromData(hexToBytes(sigHash)); } -function makeSigHashPostSign( - curSigHash: string, - pubKey: PublicKeyWire, - signature: MessageSignatureWire -): string { +/** @internal */ +function makeSigHashPostSign(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 @@ -380,7 +378,7 @@ function makeSigHashPostSign( ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed; - const sigHash = curSigHash + leftPadHex(pubKeyEncoding.toString(16)) + signature.data; + const sigHash = curSigHash + leftPadHex(pubKeyEncoding.toString(16)) + signature; const sigHashBytes = hexToBytes(sigHash); if (sigHashBytes.byteLength > hashLength) { @@ -397,7 +395,7 @@ export function nextSignature( nonce: IntegerType, privateKey: PrivateKey ): { - nextSig: MessageSignatureWire; + nextSig: string; nextSigHash: string; } { const sigHashPreSign = makeSigHashPreSign(curSigHash, authType, fee, nonce); @@ -418,7 +416,7 @@ export function nextVerification( fee: IntegerType, nonce: IntegerType, pubKeyEncoding: PubKeyEncoding, - signature: MessageSignatureWire + signature: string ) { const sigHashPreSign = makeSigHashPreSign(initialSigHash, authType, fee, nonce); @@ -465,7 +463,7 @@ function verifySingleSig( condition.fee, condition.nonce, condition.keyEncoding, - condition.signature + condition.signature.data ); // address version arg doesn't matter for signer hash generation @@ -508,7 +506,7 @@ function verifyMultiSig( condition.fee, condition.nonce, field.pubKeyEncoding, - field.contents + field.contents.data ); if (isSequentialMultiSig(condition.hashMode)) { diff --git a/packages/transactions/src/builders.ts b/packages/transactions/src/builders.ts index adfb6230e..7a60b9ceb 100644 --- a/packages/transactions/src/builders.ts +++ b/packages/transactions/src/builders.ts @@ -1,4 +1,4 @@ -import { ApiOpts, ApiParam, IntegerType } from '@stacks/common'; +import { ApiOpts, ApiParam, IntegerType, PrivateKey, PublicKey } from '@stacks/common'; import { STACKS_MAINNET, STACKS_TESTNET, @@ -28,8 +28,14 @@ import { SingleSigHashMode, } from './constants'; import { ClarityAbi, validateContractCall } from './contract-abi'; -import { fetchFeeEstimate, fetchAbi, fetchNonce } from './fetch'; -import { createStacksPublicKey, privateKeyToPublic, publicKeyToAddress } from './keys'; +import { fetchAbi, fetchFeeEstimate, fetchNonce } from './fetch'; +import { + createStacksPublicKey, + privateKeyToHex, + privateKeyToPublic, + publicKeyToAddress, + publicKeyToHex, +} from './keys'; import { postConditionToWire } from './postcondition'; import { PostCondition } from './postcondition-types'; import { TransactionSigner } from './signer'; @@ -56,7 +62,7 @@ export interface UnsignedMultiSigOptions { /** The minimum required signatures N (in a N of M multi-sig) */ numSignatures: number; /** The M public-keys (in a N of M multi-sig), which together form the address of the multi-sig account */ - publicKeys: string[]; + publicKeys: PublicKey[]; /** * The `address` of the multi-sig account. * - If NOT provided, the public-key order is taken AS IS. @@ -69,7 +75,7 @@ export interface UnsignedMultiSigOptions { } export type SignedMultiSigOptions = UnsignedMultiSigOptions & { - signerKeys: string[]; + signerKeys: PrivateKey[]; }; /** @@ -95,11 +101,11 @@ export type TokenTransferOptions = { } & ApiParam; export interface UnsignedTokenTransferOptions extends TokenTransferOptions { - publicKey: string; + publicKey: PublicKey; } export interface SignedTokenTransferOptions extends TokenTransferOptions { - senderKey: string; + senderKey: PrivateKey; } export type UnsignedMultiSigTokenTransferOptions = TokenTransferOptions & UnsignedMultiSigOptions; @@ -151,12 +157,12 @@ export async function makeUnsignedSTXTokenTransfer( const publicKeys = options.address ? sortPublicKeysForAddress( - options.publicKeys, + options.publicKeys.map(publicKeyToHex), options.numSignatures, hashMode, createAddress(options.address).hash160 ) - : options.publicKeys; + : options.publicKeys.map(publicKeyToHex); spendingCondition = createMultiSigSpendingCondition( hashMode, @@ -226,8 +232,8 @@ export async function makeSTXTokenTransfer( mutatingSignAppendMultiSig( transaction, - txOptions.publicKeys.slice(), - txOptions.signerKeys, + txOptions.publicKeys.map(publicKeyToHex).slice(), + txOptions.signerKeys.map(privateKeyToHex), txOptions.address ); @@ -262,11 +268,11 @@ export interface BaseContractDeployOptions { export interface UnsignedContractDeployOptions extends BaseContractDeployOptions { /** a hex string of the public key of the transaction sender */ - publicKey: string; + publicKey: PublicKey; } export interface SignedContractDeployOptions extends BaseContractDeployOptions { - senderKey: string; + senderKey: PrivateKey; } /** @deprecated Use {@link SignedContractDeployOptions} or {@link UnsignedContractDeployOptions} instead. */ @@ -307,8 +313,8 @@ export async function makeContractDeploy( mutatingSignAppendMultiSig( transaction, - txOptions.publicKeys.slice(), - txOptions.signerKeys, + txOptions.publicKeys.map(publicKeyToHex).slice(), + txOptions.signerKeys.map(privateKeyToHex), txOptions.address ); @@ -357,12 +363,12 @@ export async function makeUnsignedContractDeploy( const publicKeys = options.address ? sortPublicKeysForAddress( - options.publicKeys, + options.publicKeys.map(publicKeyToHex), options.numSignatures, hashMode, createAddress(options.address).hash160 ) - : options.publicKeys; + : options.publicKeys.map(publicKeyToHex); spendingCondition = createMultiSigSpendingCondition( hashMode, @@ -440,11 +446,11 @@ export interface ContractCallOptions { } export interface UnsignedContractCallOptions extends ContractCallOptions { - publicKey: string; + publicKey: PrivateKey; } export interface SignedContractCallOptions extends ContractCallOptions { - senderKey: string; + senderKey: PublicKey; } export type UnsignedMultiSigContractCallOptions = ContractCallOptions & UnsignedMultiSigOptions; @@ -514,12 +520,12 @@ export async function makeUnsignedContractCall( const publicKeys = options.address ? sortPublicKeysForAddress( - options.publicKeys, + options.publicKeys.map(publicKeyToHex), options.numSignatures, hashMode, createAddress(options.address).hash160 ) - : options.publicKeys; + : options.publicKeys.map(publicKeyToHex); spendingCondition = createMultiSigSpendingCondition( hashMode, @@ -594,8 +600,8 @@ export async function makeContractCall( mutatingSignAppendMultiSig( transaction, - txOptions.publicKeys.slice(), - txOptions.signerKeys, + txOptions.publicKeys.map(publicKeyToHex).slice(), + txOptions.signerKeys.map(privateKeyToHex), txOptions.address ); @@ -610,7 +616,7 @@ export interface SponsorOptionsOpts { /** the origin-signed transaction */ transaction: StacksTransaction; /** the sponsor's private key */ - sponsorPrivateKey: string; + sponsorPrivateKey: PrivateKey; /** the transaction fee amount to sponsor */ fee?: IntegerType; /** the nonce of the sponsor account */ diff --git a/packages/transactions/src/keys.ts b/packages/transactions/src/keys.ts index 0111a514c..897d6eba4 100644 --- a/packages/transactions/src/keys.ts +++ b/packages/transactions/src/keys.ts @@ -25,15 +25,7 @@ import { c32address } from 'c32check'; import { addressHashModeToVersion } from './address'; import { AddressHashMode, AddressVersion, PubKeyEncoding } from './constants'; import { hash160, hashP2PKH } from './utils'; -import { - addressFromVersionHash, - addressToString, - createMessageSignature, - MessageSignatureWire, - PublicKeyWire, - StacksWireType, - StructuredDataSignatureWire, -} from './wire'; +import { addressFromVersionHash, addressToString, PublicKeyWire, StacksWireType } from './wire'; /** * To use secp256k1.signSync set utils.hmacSha256Sync to a function using noble-hashes @@ -83,10 +75,10 @@ export function createStacksPublicKey(publicKey: PublicKey): PublicKeyWire { export function publicKeyFromSignatureVrs( messageHash: string, - messageSignature: MessageSignatureWire | StructuredDataSignatureWire, + messageSignature: string, pubKeyEncoding = PubKeyEncoding.Compressed ): string { - const parsedSignature = parseRecoverableSignatureVrs(messageSignature.data); + const parsedSignature = parseRecoverableSignatureVrs(messageSignature); const signature = new Signature(hexToBigInt(parsedSignature.r), hexToBigInt(parsedSignature.s)); const point = Point.fromSignature(messageHash, signature, parsedSignature.recoveryId); const compressed = pubKeyEncoding === PubKeyEncoding.Compressed; @@ -95,12 +87,12 @@ export function publicKeyFromSignatureVrs( export function publicKeyFromSignatureRsv( messageHash: string, - messageSignature: MessageSignatureWire | StructuredDataSignatureWire, + messageSignature: string, pubKeyEncoding = PubKeyEncoding.Compressed ): string { return publicKeyFromSignatureVrs( messageHash, - { ...messageSignature, data: signatureRsvToVrs(messageSignature.data) }, + signatureRsvToVrs(messageSignature), pubKeyEncoding ); } @@ -148,8 +140,7 @@ export function publicKeyIsCompressed(publicKey: PublicKey): boolean { * Allows for "compressed" and "uncompressed" private keys. * > Matches legacy `pubKeyfromPrivKey`, `getPublic` function behavior */ -export function privateKeyToPublic(privateKey: PrivateKey): string { - // todo: improve return result type `next` +export function privateKeyToPublic(privateKey: PrivateKey): PublicKey { privateKey = privateKeyToBytes(privateKey); const isCompressed = privateKeyIsCompressed(privateKey); return bytesToHex(nobleGetPublicKey(privateKey.slice(0, 32), isCompressed)); @@ -190,7 +181,7 @@ export function makeRandomPrivKey(): string { * @deprecated The Clarity compatible {@link signMessageHashRsv} is preferred, but differs in signature format * @returns A recoverable signature (in VRS order) */ -export function signWithKey(privateKey: PrivateKey, messageHash: string): MessageSignatureWire { +export function signWithKey(privateKey: PrivateKey, messageHash: string): string { privateKey = privateKeyToBytes(privateKey); const [rawSignature, recoveryId] = signSync(messageHash, privateKey.slice(0, 32), { canonical: true, @@ -200,8 +191,7 @@ export function signWithKey(privateKey: PrivateKey, messageHash: string): Messag throw new Error('No signature recoveryId received'); } const recoveryIdHex = intToHex(recoveryId, 1); - const recoverableSignatureString = recoveryIdHex + Signature.fromHex(rawSignature).toCompactHex(); // V + RS - return createMessageSignature(recoverableSignatureString); + return recoveryIdHex + Signature.fromHex(rawSignature).toCompactHex(); // V + RS } /** @@ -215,9 +205,8 @@ export function signMessageHashRsv({ }: { messageHash: string; privateKey: PrivateKey; -}): MessageSignatureWire { - const messageSignature = signWithKey(privateKey, messageHash); - return { ...messageSignature, data: signatureVrsToRsv(messageSignature.data) }; +}): string { + return signatureVrsToRsv(signWithKey(privateKey, messageHash)); } /** diff --git a/packages/transactions/src/signer.ts b/packages/transactions/src/signer.ts index 3f2a1a930..9400e58fa 100644 --- a/packages/transactions/src/signer.ts +++ b/packages/transactions/src/signer.ts @@ -50,7 +50,7 @@ export class TransactionSigner { spendingCondition.fee, spendingCondition.nonce, PubKeyEncoding.Compressed, // always compressed for multisig - signature + signature.data ); if (!isNonSequentialMultiSig(spendingCondition.hashMode)) { diff --git a/packages/transactions/src/structuredDataSignature.ts b/packages/transactions/src/structuredDataSignature.ts index 420efb608..d492bc27e 100644 --- a/packages/transactions/src/structuredDataSignature.ts +++ b/packages/transactions/src/structuredDataSignature.ts @@ -2,7 +2,6 @@ import { sha256 } from '@noble/hashes/sha256'; import { PrivateKey, bytesToHex, concatBytes, utf8ToBytes } from '@stacks/common'; import { ClarityType, ClarityValue, serializeCVBytes } from './clarity'; import { signMessageHashRsv } from './keys'; -import { StacksWireType, StructuredDataSignatureWire } from './wire'; // Refer to SIP018 https://github.com/stacksgov/sips/ // > asciiToBytes('SIP018') @@ -78,16 +77,11 @@ export function signStructuredData({ message: ClarityValue; domain: ClarityValue; privateKey: PrivateKey; -}): StructuredDataSignatureWire { - const structuredDataHash: string = bytesToHex(sha256(encodeStructuredData({ message, domain }))); +}): string { + const structuredDataHash = bytesToHex(sha256(encodeStructuredData({ message, domain }))); - const { data } = signMessageHashRsv({ + return signMessageHashRsv({ messageHash: structuredDataHash, privateKey, }); - // todo: `next` reduce wrapped signature type - return { - data, - type: StacksWireType.StructuredDataSignature, - }; } diff --git a/packages/transactions/src/transaction.ts b/packages/transactions/src/transaction.ts index 456135717..c7ec7596a 100644 --- a/packages/transactions/src/transaction.ts +++ b/packages/transactions/src/transaction.ts @@ -53,6 +53,7 @@ import { PublicKeyWire, StacksWireType, createLPList, + createMessageSignature, createTransactionAuthField, deserializeLPListBytes, deserializePayloadBytes, @@ -188,13 +189,13 @@ export class StacksTransaction { privateKey ); if (isSingleSig(condition)) { - condition.signature = nextSig; + condition.signature = createMessageSignature(nextSig); } else { const compressed = privateKeyIsCompressed(privateKey); condition.fields.push( createTransactionAuthField( compressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed, - nextSig + createMessageSignature(nextSig) ) ); } diff --git a/packages/transactions/tests/authorization.test.ts b/packages/transactions/tests/authorization.test.ts index 2312c032a..66502ccfc 100644 --- a/packages/transactions/tests/authorization.test.ts +++ b/packages/transactions/tests/authorization.test.ts @@ -22,7 +22,7 @@ test('ECDSA recoverable signature', () => { '019901d8b1d67a7b853dc473d0609508ab2519ec370eabfef460aa0fd9234660' + '787970968562da9de8b024a7f36f946b2fdcbf39b2f59247267a9d72730f19276b'; const messageSignature = signWithKey(privKey, messagetoSign); - expect(messageSignature.data).toBe(correctSignature); + expect(messageSignature).toBe(correctSignature); }); test('Single spending condition serialization and deserialization', () => { diff --git a/packages/transactions/tests/builder.test.ts b/packages/transactions/tests/builder.test.ts index d8c1aec6e..466a9865c 100644 --- a/packages/transactions/tests/builder.test.ts +++ b/packages/transactions/tests/builder.test.ts @@ -578,7 +578,7 @@ test('Make Multi-Sig STX token transfer with two transaction signers', async () const compressed1 = privKeys[0].endsWith('01'); const field1 = createTransactionAuthField( compressed1 ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed, - sig1 + createMessageSignature(sig1) ); signer.signOrigin(privKeys[0]); @@ -599,7 +599,7 @@ test('Make Multi-Sig STX token transfer with two transaction signers', async () const compressed2 = privKeys[1].endsWith('01'); const field2 = createTransactionAuthField( compressed2 ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed, - sig2 + createMessageSignature(sig2) ); const compressedPub = publicKeyIsCompressed(pubKeys[2].data); @@ -2396,9 +2396,7 @@ describe('multi-sig', () => { const signingSigs = new Set( // deduplicate - signing.map( - sk => nextSignature(tx.signBegin(), tx.auth.authType, 1_000n, 2n, sk).nextSig.data - ) + signing.map(sk => nextSignature(tx.signBegin(), tx.auth.authType, 1_000n, 2n, sk).nextSig) ); expect(signingSigs.size).toBe(signatures.length); expect(Array.from(signingSigs)).toEqual(expect.arrayContaining(signatures)); @@ -2463,7 +2461,7 @@ describe('multi-sig', () => { hexToBytes(signerKey).byteLength === PRIVATE_KEY_COMPRESSED_LENGTH ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed, - nextSig + createMessageSignature(nextSig) ); serialized = transactionToHex(tx); diff --git a/packages/transactions/tests/keys.test.ts b/packages/transactions/tests/keys.test.ts index 0eb6f52f4..ec8945a9f 100644 --- a/packages/transactions/tests/keys.test.ts +++ b/packages/transactions/tests/keys.test.ts @@ -118,7 +118,7 @@ test('signWithKey', () => { expect(messageHash).toBe(expectedMessageHash); const signature = signWithKey(privateKey, messageHash); - expect(signature.data).toBe(expectedSignatureVrs); + expect(signature).toBe(expectedSignatureVrs); }); test('signMessageHashRsv', () => { @@ -139,7 +139,7 @@ test('signMessageHashRsv', () => { expect(messageHash).toBe(expectedMessageHash); const signature = signMessageHashRsv({ privateKey, messageHash }); - expect(signature.data).toBe(expectedSignatureRsv); + expect(signature).toBe(expectedSignatureRsv); }); test('noble sign message', () => { @@ -152,7 +152,7 @@ test('noble sign message', () => { const messageHash = bytesToHex(sha256('greetings from noble')); expect(messageHash).toBe(expectedMessageHash); - const signatureRsv = signMessageHashRsv({ privateKey, messageHash }).data; + const signatureRsv = signMessageHashRsv({ privateKey, messageHash }); const signatureVrs = signatureRsvToVrs(signatureRsv); const { r: signatureR, s: signatureS } = parseRecoverableSignatureVrs(signatureVrs); diff --git a/packages/transactions/tests/structuredDataSignature.test.ts b/packages/transactions/tests/structuredDataSignature.test.ts index acac3d88f..c15c1bf54 100644 --- a/packages/transactions/tests/structuredDataSignature.test.ts +++ b/packages/transactions/tests/structuredDataSignature.test.ts @@ -229,10 +229,10 @@ describe('SIP018 test vectors', () => { domain, privateKey, }); - expect(computedSignature.data).toEqual(expectedSignature); + expect(computedSignature).toEqual(expectedSignature); // Verify signature const isSignatureVerified = verifyMessageSignatureRsv({ - signature: computedSignature.data, + signature: computedSignature, message: hexToBytes(messageHash), publicKey, }); @@ -260,11 +260,11 @@ test('verifyMessageSignature works for both legacy/current and future message si const publicKey = publicKeyFromSignatureRsv(encodedMessageHash, signature); const publicKeyAlt = publicKeyFromSignatureRsv(encodedMessageHashAlt, signatureAlt); - expect(verifyMessageSignatureRsv({ message, signature: signature.data, publicKey })).toBe(true); + expect(verifyMessageSignatureRsv({ message, signature, publicKey })).toBe(true); expect( verifyMessageSignatureRsv({ message, - signature: signatureAlt.data, + signature: signatureAlt, publicKey: publicKeyAlt, }) ).toBe(true);