diff --git a/.github/MIGRATION.md b/.github/MIGRATION.md index e67b8cc65..bff78a642 100644 --- a/.github/MIGRATION.md +++ b/.github/MIGRATION.md @@ -238,27 +238,16 @@ For easier migrating, renaming the following methods is possible to keep the pre - `StacksTransaction.serialize` → `StacksTransaction.serializeBytes` - `serializeCV` → `serializeCVBytes` - `serializeAddress` → `serializeAddressBytes` -- `deserializeAddress` → `deserializeAddressBytes` - `serializeLPList` → `serializeLPListBytes` -- `deserializeLPList` → `deserializeLPListBytes` - `serializeLPString` → `serializeLPStringBytes` -- `deserializeLPString` → `deserializeLPStringBytes` - `serializePayload` → `serializePayloadBytes` -- `deserializePayload` → `deserializePayloadBytes` - `serializePublicKey` → `serializePublicKeyBytes` -- `deserializePublicKey` → `deserializePublicKeyBytes` - `serializeStacksMessage` → `serializeStacksMessageBytes` -- `deserializeStacksMessage` → `deserializeStacksMessageBytes` - `serializeMemoString` → `serializeMemoStringBytes` -- `deserializeMemoString` → `deserializeMemoStringBytes` - `serializeTransactionAuthField` → `serializeTransactionAuthFieldBytes` -- `deserializeTransactionAuthField` → `deserializeTransactionAuthFieldBytes` - `serializeMessageSignature` → `serializeMessageSignatureBytes` -- `deserializeMessageSignature` → `deserializeMessageSignatureBytes` - `serializePostCondition` → `serializePostConditionBytes` -- `deserializePostCondition` → `deserializePostConditionBytes` - `serializeStacksMessage` → `serializeStacksWireBytes` -- `deserializeStacksMessage` → `deserializeStacksWireBytes` ### Asset Helper Methods @@ -287,7 +276,6 @@ This is only used for advanced serialization use-cases internally and should not - `StacksMessage` → `StacksWire` - `StacksMessageType` → `StacksWireType` - `serializeStacksMessage` → `serializeStacksWireBytes` -- `deserializeStacksMessage` → `deserializeStacksWireBytes` More types were renamed to indicate use for serialization to _wire-format_: diff --git a/packages/transactions/src/BytesReader.ts b/packages/transactions/src/BytesReader.ts index 334885241..0f0c79d3b 100644 --- a/packages/transactions/src/BytesReader.ts +++ b/packages/transactions/src/BytesReader.ts @@ -1,4 +1,4 @@ -import { bytesToHex, readUInt16BE, readUInt32BE, readUInt8 } from '@stacks/common'; +import { bytesToHex, hexToBytes, readUInt16BE, readUInt32BE, readUInt8 } from '@stacks/common'; function createEnumChecker(enumVariable: { [key in T]: TEnumValue; @@ -47,8 +47,8 @@ export class BytesReader { source: Uint8Array; consumed: number = 0; - constructor(arr: Uint8Array) { - this.source = arr; + constructor(bytes: string | Uint8Array) { + this.source = typeof bytes === 'string' ? hexToBytes(bytes) : bytes; } readBytes(length: number): Uint8Array { diff --git a/packages/transactions/src/authorization.ts b/packages/transactions/src/authorization.ts index 764b90b35..ac50f1be4 100644 --- a/packages/transactions/src/authorization.ts +++ b/packages/transactions/src/authorization.ts @@ -31,8 +31,8 @@ import { addressFromPublicKeys, createEmptyAddress, createLPList, - deserializeLPListBytes, - deserializeMessageSignatureBytes, + deserializeLPList, + deserializeMessageSignature, MessageSignatureWire, PublicKeyWire, serializeLPListBytes, @@ -258,7 +258,7 @@ export function deserializeSingleSigSpendingCondition( 'Failed to parse singlesig spending condition: incomaptible hash mode and key encoding' ); } - const signature = deserializeMessageSignatureBytes(bytesReader); + const signature = deserializeMessageSignature(bytesReader); return { hashMode, signer, @@ -277,7 +277,7 @@ export function deserializeMultiSigSpendingCondition( const nonce = BigInt('0x' + bytesToHex(bytesReader.readBytes(8))); const fee = BigInt('0x' + bytesToHex(bytesReader.readBytes(8))); - const fields = deserializeLPListBytes(bytesReader, StacksWireType.TransactionAuthField) + const fields = deserializeLPList(bytesReader, StacksWireType.TransactionAuthField) .values as TransactionAuthFieldWire[]; let haveUncompressed = false; diff --git a/packages/transactions/src/clarity/deserialize.ts b/packages/transactions/src/clarity/deserialize.ts index 6e2a2023f..55de2bbc7 100644 --- a/packages/transactions/src/clarity/deserialize.ts +++ b/packages/transactions/src/clarity/deserialize.ts @@ -20,7 +20,7 @@ import { } from '.'; import { BytesReader } from '../BytesReader'; import { DeserializationError } from '../errors'; -import { deserializeAddressBytes, deserializeLPStringBytes } from '../wire'; +import { deserializeAddress, deserializeLPString } from '../wire'; /** * Deserializes clarity value to clarity type @@ -75,12 +75,12 @@ export function deserializeCV( return falseCV() as T; case ClarityWireType.address: - const sAddress = deserializeAddressBytes(bytesReader); + const sAddress = deserializeAddress(bytesReader); return standardPrincipalCVFromAddress(sAddress) as T; case ClarityWireType.contract: - const cAddress = deserializeAddressBytes(bytesReader); - const contractName = deserializeLPStringBytes(bytesReader); + const cAddress = deserializeAddress(bytesReader); + const contractName = deserializeLPString(bytesReader); return contractPrincipalCVFromAddress(cAddress, contractName) as T; case ClarityWireType.ok: @@ -107,7 +107,7 @@ export function deserializeCV( const tupleLength = bytesReader.readUInt32BE(); const tupleContents: { [key: string]: ClarityValue } = {}; for (let i = 0; i < tupleLength; i++) { - const clarityName = deserializeLPStringBytes(bytesReader).content; + const clarityName = deserializeLPString(bytesReader).content; if (clarityName === undefined) { throw new DeserializationError('"content" is undefined'); } diff --git a/packages/transactions/src/transaction.ts b/packages/transactions/src/transaction.ts index 690512414..42991063e 100644 --- a/packages/transactions/src/transaction.ts +++ b/packages/transactions/src/transaction.ts @@ -5,8 +5,8 @@ import { PublicKey, bytesToHex, concatArray, - hexToBytes, intToBigInt, + isInstance, writeUInt32BE, } from '@stacks/common'; import { @@ -56,8 +56,8 @@ import { createLPList, createMessageSignature, createTransactionAuthField, - deserializeLPListBytes, - deserializePayloadBytes, + deserializeLPList, + deserializePayload, serializeLPListBytes, } from './wire'; @@ -312,18 +312,7 @@ export class StacksTransaction { * @param tx hex string or bytes of serialized transaction */ export function deserializeTransaction(tx: string | Uint8Array | BytesReader) { - let bytesReader: BytesReader; // todo: add readerFrom method - if (typeof tx === 'string') { - if (tx.slice(0, 2).toLowerCase() === '0x') { - bytesReader = new BytesReader(hexToBytes(tx.slice(2))); - } else { - bytesReader = new BytesReader(hexToBytes(tx)); - } - } else if (tx instanceof Uint8Array) { - bytesReader = new BytesReader(tx); - } else { - bytesReader = tx; - } + const bytesReader = isInstance(tx, BytesReader) ? tx : new BytesReader(tx); const version = bytesReader.readUInt8Enum(TransactionVersion, n => { throw new Error(`Could not parse ${n} as TransactionVersion`); }); @@ -335,8 +324,8 @@ export function deserializeTransaction(tx: string | Uint8Array | BytesReader) { const postConditionMode = bytesReader.readUInt8Enum(PostConditionMode, n => { throw new Error(`Could not parse ${n} as PostConditionMode`); }); - const postConditions = deserializeLPListBytes(bytesReader, StacksWireType.PostCondition); - const payload = deserializePayloadBytes(bytesReader); + const postConditions = deserializeLPList(bytesReader, StacksWireType.PostCondition); + const payload = deserializePayload(bytesReader); return new StacksTransaction( version, diff --git a/packages/transactions/src/wire/serialization.ts b/packages/transactions/src/wire/serialization.ts index 9604763b0..eed1993fe 100644 --- a/packages/transactions/src/wire/serialization.ts +++ b/packages/transactions/src/wire/serialization.ts @@ -108,35 +108,35 @@ export function serializeStacksWireBytes(wire: StacksWire): Uint8Array { } /** @internal */ -export function deserializeStacksWireBytes( - bytesReader: BytesReader, +export function deserializeStacksWire( + bytesReader: string | Uint8Array | BytesReader, type: StacksWireType, listType?: StacksWireType ): StacksWire { switch (type) { case StacksWireType.Address: - return deserializeAddressBytes(bytesReader); + return deserializeAddress(bytesReader); case StacksWireType.Principal: - return deserializePrincipalBytes(bytesReader); + return deserializePrincipal(bytesReader); case StacksWireType.LengthPrefixedString: - return deserializeLPStringBytes(bytesReader); + return deserializeLPString(bytesReader); case StacksWireType.MemoString: - return deserializeMemoStringBytes(bytesReader); + return deserializeMemoString(bytesReader); case StacksWireType.Asset: - return deserializeAssetBytes(bytesReader); + return deserializeAsset(bytesReader); case StacksWireType.PostCondition: - return deserializePostConditionBytes(bytesReader); + return deserializePostCondition(bytesReader); case StacksWireType.PublicKey: - return deserializePublicKeyBytes(bytesReader); + return deserializePublicKey(bytesReader); case StacksWireType.Payload: - return deserializePayloadBytes(bytesReader); + return deserializePayload(bytesReader); case StacksWireType.LengthPrefixedList: if (!listType) { throw new DeserializationError('No list type specified'); } - return deserializeLPListBytes(bytesReader, listType); + return deserializeLPList(bytesReader, listType); case StacksWireType.MessageSignature: - return deserializeMessageSignatureBytes(bytesReader); + return deserializeMessageSignature(bytesReader); default: throw new Error('Could not recognize StacksWireType'); } @@ -153,11 +153,8 @@ export function serializeAddressBytes(address: AddressWire): Uint8Array { return concatArray(bytesArray); } -export function deserializeAddress(serialized: string): AddressWire { - return deserializeAddressBytes(hexToBytes(serialized)); -} /** @internal */ -export function deserializeAddressBytes(serialized: Uint8Array | BytesReader): AddressWire { +export function deserializeAddress(serialized: string | Uint8Array | BytesReader): AddressWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized : new BytesReader(serialized); @@ -186,12 +183,9 @@ export function serializePrincipalBytes(principal: PostConditionPrincipalWire): return concatArray(bytesArray); } -export function deserializePrincipal(serialized: string): PostConditionPrincipalWire { - return deserializePrincipalBytes(hexToBytes(serialized)); -} /** @internal */ -export function deserializePrincipalBytes( - serialized: Uint8Array | BytesReader +export function deserializePrincipal( + serialized: string | Uint8Array | BytesReader ): PostConditionPrincipalWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized @@ -202,11 +196,11 @@ export function deserializePrincipalBytes( if (prefix === PostConditionPrincipalId.Origin) { return { type: StacksWireType.Principal, prefix } as OriginPrincipalWire; } - const address = deserializeAddressBytes(bytesReader); + const address = deserializeAddress(bytesReader); if (prefix === PostConditionPrincipalId.Standard) { return { type: StacksWireType.Principal, prefix, address } as StandardPrincipalWire; } - const contractName = deserializeLPStringBytes(bytesReader); + const contractName = deserializeLPString(bytesReader); return { type: StacksWireType.Principal, prefix, @@ -228,16 +222,9 @@ export function serializeLPStringBytes(lps: LengthPrefixedStringWire): Uint8Arra return concatArray(bytesArray); } -export function deserializeLPString( - serialized: string, - prefixBytes?: number, - maxLength?: number -): LengthPrefixedStringWire { - return deserializeLPStringBytes(hexToBytes(serialized), prefixBytes, maxLength); -} /** @internal */ -export function deserializeLPStringBytes( - serialized: Uint8Array | BytesReader, +export function deserializeLPString( + serialized: string | Uint8Array | BytesReader, prefixBytes?: number, maxLength?: number ): LengthPrefixedStringWire { @@ -262,11 +249,10 @@ export function serializeMemoStringBytes(memoString: MemoStringWire): Uint8Array return concatArray(bytesArray); } -export function deserializeMemoString(serialized: string): MemoStringWire { - return deserializeMemoStringBytes(hexToBytes(serialized)); -} /** @internal */ -export function deserializeMemoStringBytes(serialized: Uint8Array | BytesReader): MemoStringWire { +export function deserializeMemoString( + serialized: string | Uint8Array | BytesReader +): MemoStringWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized : new BytesReader(serialized); @@ -287,19 +273,16 @@ export function serializeAssetBytes(info: AssetWire): Uint8Array { return concatArray(bytesArray); } -export function deserializeAsset(serialized: string): AssetWire { - return deserializeAssetBytes(hexToBytes(serialized)); -} /** @internal */ -export function deserializeAssetBytes(serialized: Uint8Array | BytesReader): AssetWire { +export function deserializeAsset(serialized: string | Uint8Array | BytesReader): AssetWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized : new BytesReader(serialized); return { type: StacksWireType.Asset, - address: deserializeAddressBytes(bytesReader), - contractName: deserializeLPStringBytes(bytesReader), - assetName: deserializeLPStringBytes(bytesReader), + address: deserializeAddress(bytesReader), + contractName: deserializeLPString(bytesReader), + assetName: deserializeLPString(bytesReader), }; } @@ -317,19 +300,12 @@ export function serializeLPListBytes(lpList: LengthPrefixedList): Uint8Array { return concatArray(bytesArray); } -// todo: `next` refactor for inversion of control -export function deserializeLPList( - serialized: string, - type: StacksWireType, - lengthPrefixBytes?: number -): LengthPrefixedList { - return deserializeLPListBytes(hexToBytes(serialized), type, lengthPrefixBytes); -} /** @internal */ -export function deserializeLPListBytes( - serialized: Uint8Array | BytesReader, +export function deserializeLPList( + serialized: string | Uint8Array | BytesReader, type: StacksWireType, lengthPrefixBytes?: number + // todo: `next` refactor for inversion of control ): LengthPrefixedList { const bytesReader = isInstance(serialized, BytesReader) ? serialized @@ -340,25 +316,25 @@ export function deserializeLPListBytes( for (let index = 0; index < length; index++) { switch (type) { case StacksWireType.Address: - l.push(deserializeAddressBytes(bytesReader)); + l.push(deserializeAddress(bytesReader)); break; case StacksWireType.LengthPrefixedString: - l.push(deserializeLPStringBytes(bytesReader)); + l.push(deserializeLPString(bytesReader)); break; case StacksWireType.MemoString: - l.push(deserializeMemoStringBytes(bytesReader)); + l.push(deserializeMemoString(bytesReader)); break; case StacksWireType.Asset: - l.push(deserializeAssetBytes(bytesReader)); + l.push(deserializeAsset(bytesReader)); break; case StacksWireType.PostCondition: - l.push(deserializePostConditionBytes(bytesReader)); + l.push(deserializePostCondition(bytesReader)); break; case StacksWireType.PublicKey: - l.push(deserializePublicKeyBytes(bytesReader)); + l.push(deserializePublicKey(bytesReader)); break; case StacksWireType.TransactionAuthField: - l.push(deserializeTransactionAuthFieldBytes(bytesReader)); + l.push(deserializeTransactionAuthField(bytesReader)); break; } } @@ -400,12 +376,9 @@ export function serializePostConditionBytes(postCondition: PostConditionWire): U return concatArray(bytesArray); } -export function deserializePostCondition(serialized: string): PostConditionWire { - return deserializePostConditionBytes(hexToBytes(serialized)); -} /** @internal */ -export function deserializePostConditionBytes( - serialized: Uint8Array | BytesReader +export function deserializePostCondition( + serialized: string | Uint8Array | BytesReader ): PostConditionWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized @@ -414,7 +387,7 @@ export function deserializePostConditionBytes( throw new DeserializationError(`Could not read ${n} as PostConditionType`); }); - const principal = deserializePrincipalBytes(bytesReader); + const principal = deserializePrincipal(bytesReader); let conditionCode; let asset; @@ -433,7 +406,7 @@ export function deserializePostConditionBytes( amount, }; case PostConditionType.Fungible: - asset = deserializeAssetBytes(bytesReader); + asset = deserializeAsset(bytesReader); conditionCode = bytesReader.readUInt8Enum(FungibleConditionCode, n => { throw new DeserializationError(`Could not read ${n} as FungibleConditionCode`); }); @@ -447,7 +420,7 @@ export function deserializePostConditionBytes( asset: asset, }; case PostConditionType.NonFungible: - asset = deserializeAssetBytes(bytesReader); + asset = deserializeAsset(bytesReader); const assetName = deserializeCV(bytesReader); conditionCode = bytesReader.readUInt8Enum(NonFungibleConditionCode, n => { throw new DeserializationError(`Could not read ${n} as FungibleConditionCode`); @@ -457,7 +430,7 @@ export function deserializePostConditionBytes( conditionType: PostConditionType.NonFungible, principal, conditionCode, - asset: asset, + asset, assetName, }; } @@ -526,11 +499,8 @@ export function serializePayloadBytes(payload: PayloadInput): Uint8Array { return concatArray(bytesArray); } -export function deserializePayload(serialized: string): PayloadWire { - return deserializePayloadBytes(hexToBytes(serialized)); -} /** @ignore */ -export function deserializePayloadBytes(serialized: Uint8Array | BytesReader): PayloadWire { +export function deserializePayload(serialized: string | Uint8Array | BytesReader): PayloadWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized : new BytesReader(serialized); @@ -542,12 +512,12 @@ export function deserializePayloadBytes(serialized: Uint8Array | BytesReader): P case PayloadType.TokenTransfer: const recipient = deserializeCV(bytesReader) as PrincipalCV; const amount = intToBigInt(bytesReader.readBytes(8)); - const memo = deserializeMemoStringBytes(bytesReader); + const memo = deserializeMemoString(bytesReader); return createTokenTransferPayload(recipient, amount, memo); case PayloadType.ContractCall: - const contractAddress = deserializeAddressBytes(bytesReader); - const contractCallName = deserializeLPStringBytes(bytesReader); - const functionName = deserializeLPStringBytes(bytesReader); + const contractAddress = deserializeAddress(bytesReader); + const contractCallName = deserializeLPString(bytesReader); + const functionName = deserializeLPString(bytesReader); const functionArgs: ClarityValue[] = []; const numberOfArgs = bytesReader.readUInt32BE(); for (let i = 0; i < numberOfArgs; i++) { @@ -561,16 +531,16 @@ export function deserializePayloadBytes(serialized: Uint8Array | BytesReader): P functionArgs ); case PayloadType.SmartContract: - const smartContractName = deserializeLPStringBytes(bytesReader); - const codeBody = deserializeLPStringBytes(bytesReader, 4, 100_000); + const smartContractName = deserializeLPString(bytesReader); + const codeBody = deserializeLPString(bytesReader, 4, 100_000); return createSmartContractPayload(smartContractName, codeBody); case PayloadType.VersionedSmartContract: { const clarityVersion = bytesReader.readUInt8Enum(ClarityVersion, n => { throw new Error(`Cannot recognize ClarityVersion: ${n}`); }); - const smartContractName = deserializeLPStringBytes(bytesReader); - const codeBody = deserializeLPStringBytes(bytesReader, 4, 100_000); + const smartContractName = deserializeLPString(bytesReader); + const codeBody = deserializeLPString(bytesReader, 4, 100_000); return createSmartContractPayload(smartContractName, codeBody, clarityVersion); } case PayloadType.PoisonMicroblock: @@ -613,12 +583,9 @@ export function deserializePayloadBytes(serialized: Uint8Array | BytesReader): P } } -export function deserializeMessageSignature(serialized: string): MessageSignatureWire { - return deserializeMessageSignatureBytes(hexToBytes(serialized)); -} /** @ignore */ -export function deserializeMessageSignatureBytes( - serialized: Uint8Array | BytesReader +export function deserializeMessageSignature( + serialized: string | Uint8Array | BytesReader ): MessageSignatureWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized @@ -628,12 +595,9 @@ export function deserializeMessageSignatureBytes( ); } -export function deserializeTransactionAuthField(serialized: string): TransactionAuthFieldWire { - return deserializeTransactionAuthFieldBytes(hexToBytes(serialized)); -} /** @ignore */ -export function deserializeTransactionAuthFieldBytes( - serialized: Uint8Array | BytesReader +export function deserializeTransactionAuthField( + serialized: string | Uint8Array | BytesReader ): TransactionAuthFieldWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized @@ -646,22 +610,22 @@ export function deserializeTransactionAuthFieldBytes( case AuthFieldType.PublicKeyCompressed: return createTransactionAuthField( PubKeyEncoding.Compressed, - deserializePublicKeyBytes(bytesReader) + deserializePublicKey(bytesReader) ); case AuthFieldType.PublicKeyUncompressed: return createTransactionAuthField( PubKeyEncoding.Uncompressed, - createStacksPublicKey(uncompressPublicKey(deserializePublicKeyBytes(bytesReader).data)) + createStacksPublicKey(uncompressPublicKey(deserializePublicKey(bytesReader).data)) ); case AuthFieldType.SignatureCompressed: return createTransactionAuthField( PubKeyEncoding.Compressed, - deserializeMessageSignatureBytes(bytesReader) + deserializeMessageSignature(bytesReader) ); case AuthFieldType.SignatureUncompressed: return createTransactionAuthField( PubKeyEncoding.Uncompressed, - deserializeMessageSignatureBytes(bytesReader) + deserializeMessageSignature(bytesReader) ); default: throw new Error(`Unknown auth field type: ${JSON.stringify(authFieldType)}`); @@ -713,11 +677,8 @@ export function serializePublicKeyBytes(key: PublicKeyWire): Uint8Array { return key.data.slice(); } -export function deserializePublicKey(serialized: string): PublicKeyWire { - return deserializePublicKeyBytes(hexToBytes(serialized)); -} /** @ignore */ -export function deserializePublicKeyBytes(serialized: Uint8Array | BytesReader): PublicKeyWire { +export function deserializePublicKey(serialized: string | Uint8Array | BytesReader): PublicKeyWire { const bytesReader = isInstance(serialized, BytesReader) ? serialized : new BytesReader(serialized); diff --git a/packages/transactions/tests/authorization.test.ts b/packages/transactions/tests/authorization.test.ts index 66502ccfc..8b7685cbb 100644 --- a/packages/transactions/tests/authorization.test.ts +++ b/packages/transactions/tests/authorization.test.ts @@ -458,12 +458,12 @@ test('Invalid spending conditions', () => { badHashModeSinglesigBytesParseable ); - const deserializedBadHashModeSinglesigBytesParseable = deserializeSpendingCondition( + const deserializedBadHashModeSinglesig = deserializeSpendingCondition( new BytesReader(badHashModeSinglesigBytesParseableBuffer) ); // corrupt but will parse with trailing bits - expect(deserializedBadHashModeSinglesigBytesParseable).toBeTruthy(); + expect(deserializedBadHashModeSinglesig).toBeTruthy(); // wrong number of public keys (too many signatures) // prettier-ignore diff --git a/packages/transactions/tests/clarity.test.ts b/packages/transactions/tests/clarity.test.ts index 655913386..1b82e4b7d 100644 --- a/packages/transactions/tests/clarity.test.ts +++ b/packages/transactions/tests/clarity.test.ts @@ -1,6 +1,6 @@ import { asciiToBytes, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes } from '@stacks/common'; import assert from 'assert'; -import { Cl, deserializeAddressBytes } from '../src'; +import { Cl, deserializeAddress } from '../src'; import { BytesReader } from '../src/BytesReader'; import { BufferCV, @@ -491,9 +491,7 @@ describe('Clarity Types', () => { 0x11, 0xab, 0xab, 0xff, 0xff, ]); const bytesReader = new BytesReader(concatBytes(new Uint8Array([0x00]), addressBuffer)); - const standardPrincipal = standardPrincipalCVFromAddress( - deserializeAddressBytes(bytesReader) - ); + const standardPrincipal = standardPrincipalCVFromAddress(deserializeAddress(bytesReader)); const serialized = serializeCV(standardPrincipal); expect(serialized).toEqual('050011deadbeef11ababffff11deadbeef11ababffff'); }); @@ -505,9 +503,7 @@ describe('Clarity Types', () => { ]); const contractName = 'abcd'; const bytesReader = new BytesReader(concatBytes(new Uint8Array([0x00]), addressBuffer)); - const standardPrincipal = standardPrincipalCVFromAddress( - deserializeAddressBytes(bytesReader) - ); + const standardPrincipal = standardPrincipalCVFromAddress(deserializeAddress(bytesReader)); const contractPrincipal = contractPrincipalCVFromStandard(standardPrincipal, contractName); const serialized = serializeCV(contractPrincipal); expect(serialized).toEqual('060011deadbeef11ababffff11deadbeef11ababffff0461626364'); diff --git a/packages/transactions/tests/macros.ts b/packages/transactions/tests/macros.ts index 09a1629f4..c5bb0626b 100644 --- a/packages/transactions/tests/macros.ts +++ b/packages/transactions/tests/macros.ts @@ -1,7 +1,7 @@ import { StacksWire, StacksWireType, - deserializeStacksWireBytes, + deserializeStacksWire, serializeStacksWireBytes, } from '../src'; import { BytesReader } from '../src/BytesReader'; @@ -12,5 +12,5 @@ export function serializeDeserialize { const serialized = serializeStacksWireBytes(lpList); const bytesReader = new BytesReader(serialized); - const deserialized = deserializeLPListBytes(bytesReader, StacksWireType.Address); + const deserialized = deserializeLPList(bytesReader, StacksWireType.Address); expect(deserialized.values.length).toBe(addressList.length);