Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/messaging/lib/messages/ContractDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class NumericalDescriptor
// Parse payout function - need to calculate its size to avoid consuming all bytes
const payoutFunctionStartPos = reader.position;
const tempPayoutFunction = PayoutFunction.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
instance.payoutFunction = tempPayoutFunction;

Expand All @@ -222,7 +222,7 @@ export class NumericalDescriptor

// Parse remaining bytes as rounding intervals
instance.roundingIntervals = RoundingIntervals.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

return instance;
Expand Down
12 changes: 6 additions & 6 deletions packages/messaging/lib/messages/ContractInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class SingleContractInfo extends ContractInfo implements IDlcMessage {

// Read contract descriptor as sibling type (starts with its own type prefix)
instance.contractDescriptor = ContractDescriptor.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
// Skip past the contract descriptor we just read
const descLength = instance.contractDescriptor.serialize().length;
Expand All @@ -134,12 +134,12 @@ export class SingleContractInfo extends ContractInfo implements IDlcMessage {
if (oracleType === 0) {
// Single oracle
instance.oracleInfo = SingleOracleInfo.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
} else if (oracleType === 1) {
// Multi oracle
instance.oracleInfo = MultiOracleInfo.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
} else {
throw new Error(`Unknown oracle info type: ${oracleType}`);
Expand Down Expand Up @@ -277,7 +277,7 @@ export class DisjointContractInfo extends ContractInfo implements IDlcMessage {
for (let i = 0; i < numDisjointEvents; i++) {
// Read contract descriptor as sibling type (starts with its own type prefix)
const contractDescriptor = ContractDescriptor.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
// Skip past the contract descriptor we just read
const descLength = contractDescriptor.serialize().length;
Expand All @@ -290,12 +290,12 @@ export class DisjointContractInfo extends ContractInfo implements IDlcMessage {
if (oracleType === 0) {
// Single oracle
oracleInfo = SingleOracleInfo.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
} else if (oracleType === 1) {
// Multi oracle
oracleInfo = MultiOracleInfo.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
} else {
throw new Error(`Unknown oracle info type: ${oracleType}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/lib/messages/DlcAccept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class DlcAccept implements IDlcMessage {
for (let i = 0; i < fundingInputsLen; i++) {
// FundingInput body is serialized directly without TLV wrapper in rust-dlc format
const fundingInput = FundingInput.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
instance.fundingInputs.push(fundingInput);

Expand All @@ -219,7 +219,7 @@ export class DlcAccept implements IDlcMessage {
if (parseCets) {
// Read CET adaptor signatures directly to match serialize format (no TLV wrapping)
instance.cetAdaptorSignatures = CetAdaptorSignatures.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

// Skip past the CET adaptor signatures we just read
Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/lib/messages/DlcClose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class DlcClose implements IDlcMessage {
for (let i = 0; i < fundingInputsLen; i++) {
// FundingInput body is serialized directly without TLV wrapper in rust-dlc format
const fundingInput = FundingInput.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
instance.fundingInputs.push(fundingInput);

Expand All @@ -139,7 +139,7 @@ export class DlcClose implements IDlcMessage {

// Handle FundingSignatures - deserialize raw data (no TLV wrapper) like DlcSign
instance.fundingSignatures = FundingSignatures.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

// Skip past the funding signatures we just read
Expand Down
10 changes: 6 additions & 4 deletions packages/messaging/lib/messages/DlcOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ export class DlcOffer implements IDlcMessage {
reader.position,
reader.position + 5,
);
const possibleProtocolVersion = nextBytes.readUInt32BE(0);
const possibleContractFlags = nextBytes.readUInt8(4);
const nextBytesBuffer = Buffer.from(nextBytes);
const nextBytesReader = new BufferReader(nextBytesBuffer);
const possibleProtocolVersion = nextBytesReader.readUInt32BE();
const possibleContractFlags = nextBytesReader.readUInt8();

// Heuristic: protocol_version should be 1, contract_flags should be 0
// If first 4 bytes are reasonable protocol version (1-10) and next byte is 0, assume new format
Expand All @@ -160,7 +162,7 @@ export class DlcOffer implements IDlcMessage {

// ContractInfo is serialized as sibling type in dlcspecs PR #163 format
instance.contractInfo = ContractInfo.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
// Skip past the ContractInfo we just read
const contractInfoLength = instance.contractInfo.serialize().length;
Expand All @@ -177,7 +179,7 @@ export class DlcOffer implements IDlcMessage {
for (let i = 0; i < fundingInputsLen; i++) {
// FundingInput body is serialized directly without TLV wrapper in rust-dlc format
const fundingInput = FundingInput.deserializeBody(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
instance.fundingInputs.push(fundingInput);

Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/lib/messages/DlcSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class DlcSign implements IDlcMessage {

// Read CET adaptor signatures directly to match serialize format (no TLV wrapping)
instance.cetAdaptorSignatures = CetAdaptorSignatures.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

// Skip past the CET adaptor signatures we just read
Expand All @@ -167,7 +167,7 @@ export class DlcSign implements IDlcMessage {

// Read funding signatures directly to match serialize format (no TLV wrapping)
instance.fundingSignatures = FundingSignatures.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

// Skip past the funding signatures we just read
Expand Down
8 changes: 5 additions & 3 deletions packages/messaging/lib/messages/OrderOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ export class OrderOffer implements IDlcMessage {
reader.position,
reader.position + 5,
);
const possibleProtocolVersion = nextBytes.readUInt32BE(0);
const possibleContractFlags = nextBytes.readUInt8(4);
const nextBytesBuffer = Buffer.from(nextBytes);
const nextBytesReader = new BufferReader(nextBytesBuffer);
const possibleProtocolVersion = nextBytesReader.readUInt32BE();
const possibleContractFlags = nextBytesReader.readUInt8();

// Heuristic: protocol_version should be 1, contract_flags should be 0
const isNewFormat =
Expand All @@ -116,7 +118,7 @@ export class OrderOffer implements IDlcMessage {

// ContractInfo is serialized as sibling type in dlcspecs PR #163 format
instance.contractInfo = ContractInfo.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);
// Skip past the ContractInfo we just read
const contractInfoLength = instance.contractInfo.serialize().length;
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/lib/messages/PayoutFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PayoutFunction implements IDlcMessage {
// Read payout curve piece
const payoutCurvePieceStartPos = reader.position;
const payoutCurvePiece = PayoutCurvePiece.deserialize(
reader.buffer.subarray(reader.position),
Buffer.from(reader.buffer.subarray(reader.position)),
);

// Skip past the payout curve piece bytes
Expand Down
Loading