From a58e70eb16da82e81c660aabc6eaaed87c35c6be Mon Sep 17 00:00:00 2001 From: LukasDeco Date: Wed, 20 Nov 2024 09:16:09 -0700 Subject: [PATCH 1/8] feat: change encoding of order message to use hex+utf-8 --- sdk/src/driftClient.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 48f6bd86c..4ba0a11df 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5786,19 +5786,17 @@ export class DriftClient { public signSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage ): Buffer { - const takerOrderParamsMessage = Uint8Array.from( - digest(this.encodeSwiftOrderParamsMessage(orderParamsMessage)) - ); - return this.signMessage(takerOrderParamsMessage); + const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage); + return this.signMessage(new TextEncoder().encode(takerOrderParamsMessage)); } public encodeSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage - ): Buffer { - return this.program.coder.types.encode( + ): string { + return digest(this.program.coder.types.encode( 'SwiftOrderParamsMessage', orderParamsMessage - ); + )).toString("hex"); } public decodeSwiftOrderParamsMessage( From cb4dd1bf70a653550296f8712609ef3b0e490f4c Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Wed, 20 Nov 2024 10:56:06 -0500 Subject: [PATCH 2/8] accept swift taker order as hexified digest --- Cargo.lock | 1 + programs/drift/Cargo.toml | 1 + programs/drift/src/instructions/keeper.rs | 12 ++++++------ programs/drift/src/macros.rs | 9 +++++++++ programs/drift/src/validation/sig_verification.rs | 14 +++++++++----- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1e8c4e10..bb93b8ef3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,6 +886,7 @@ dependencies = [ "bytes", "drift-macros", "enumflags2", + "hex", "num-derive 0.3.3", "num-integer", "num-traits", diff --git a/programs/drift/Cargo.toml b/programs/drift/Cargo.toml index 54c515a72..ba52b50db 100644 --- a/programs/drift/Cargo.toml +++ b/programs/drift/Cargo.toml @@ -26,6 +26,7 @@ pythnet-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e pyth-solana-receiver-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e8a24ecd0bcf22b787313e2020f4186bb22c729"} bytemuck = { version = "1.4.0" } borsh = "0.10.3" +hex = "0.4.3" num-traits = "0.2" uint = { version = "0.9.1", default-features = false } num-derive = "0.3" diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index 70d6bd0f2..6ea54f04b 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -1,5 +1,5 @@ use std::cell::RefMut; -use std::convert::TryFrom; +use std::convert::{TryFrom, TryInto}; use anchor_lang::prelude::*; use anchor_spl::associated_token::get_associated_token_address; @@ -60,10 +60,10 @@ use crate::state::user::{ MarginMode, MarketType, OrderStatus, OrderTriggerCondition, OrderType, User, UserStats, }; use crate::state::user_map::{load_user_map, load_user_maps, UserMap, UserStatsMap}; -use crate::validation::sig_verification::{extract_ed25519_ix_signature, verify_ed25519_digest}; +use crate::validation::sig_verification::{extract_ed25519_ix_signature, verify_ed25519_msg}; use crate::validation::user::{validate_user_deletion, validate_user_is_idle}; use crate::{ - controller, digest_struct, load, math, print_error, safe_decrement, OracleSource, + controller, digest_struct, digest_struct_hex, load, math, print_error, safe_decrement, OracleSource, GOV_SPOT_MARKET_INDEX, MARGIN_PRECISION, }; use crate::{load_mut, QUOTE_PRECISION_U64}; @@ -597,7 +597,7 @@ pub fn place_swift_taker_order<'c: 'info, 'info>( // Verify data from first verify ix let ix: Instruction = load_instruction_at_checked(ix_idx as usize - 2, ix_sysvar)?; - verify_ed25519_digest( + verify_ed25519_msg( &ix, &swift_server::id().to_bytes(), &digest_struct!(swift_message), @@ -605,10 +605,10 @@ pub fn place_swift_taker_order<'c: 'info, 'info>( // Verify data from second verify ix let ix: Instruction = load_instruction_at_checked(ix_idx as usize - 1, ix_sysvar)?; - verify_ed25519_digest( + verify_ed25519_msg( &ix, &taker.authority.to_bytes(), - &digest_struct!(&taker_order_params_message), + digest_struct_hex!(taker_order_params_message), )?; // Verify that sig from swift server corresponds to order message diff --git a/programs/drift/src/macros.rs b/programs/drift/src/macros.rs index af5555120..34bd89b45 100644 --- a/programs/drift/src/macros.rs +++ b/programs/drift/src/macros.rs @@ -89,9 +89,18 @@ macro_rules! safe_decrement { }}; } +/// Calculate the sha256 digest of anchor encoded `struct` #[macro_export] macro_rules! digest_struct { ($struct:expr) => { solana_program::hash::hash(&$struct.try_to_vec().unwrap()).to_bytes() }; } + +/// Calculate the hexified sha256 digest of anchor encoded `struct` +#[macro_export] +macro_rules! digest_struct_hex { + ($struct:expr) => { + arrayref::array_ref!(hex::encode(digest_struct!($struct)).as_bytes(), 0, 64) + }; +} diff --git a/programs/drift/src/validation/sig_verification.rs b/programs/drift/src/validation/sig_verification.rs index 297bf60f2..7a840d572 100644 --- a/programs/drift/src/validation/sig_verification.rs +++ b/programs/drift/src/validation/sig_verification.rs @@ -79,15 +79,19 @@ fn check_ed25519_data(data: &[u8], pubkey: &[u8], msg: &[u8], sig: &[u8]) -> Res Ok(()) } -/// Check Ed25519Program instruction data verifies the given digest +/// Check Ed25519Program instruction data verifies the given msg /// /// `ix` an Ed25519Program instruction [see](https://github.com/solana-labs/solana/blob/master/sdk/src/ed25519_instruction.rs)) /// -/// `digest` expected digest signed by the offchain client i.e 'sha256(appMessage.serialize())' +/// `msg` expected msg signed by the offchain client e.g 'sha256(appMessage.serialize())' for a digest /// /// `pubkey` expected pubkey of the signer /// -pub fn verify_ed25519_digest(ix: &Instruction, pubkey: &[u8; 32], digest: &[u8; 32]) -> Result<()> { +pub fn verify_ed25519_msg( + ix: &Instruction, + pubkey: &[u8; 32], + msg: &[u8; N], +) -> Result<()> { if ix.program_id != ED25519_ID || ix.accounts.len() != 0 { msg!("Invalid Ix: program ID: {:?}", ix.program_id); msg!("Invalid Ix: accounts: {:?}", ix.accounts.len()); @@ -100,7 +104,7 @@ pub fn verify_ed25519_digest(ix: &Instruction, pubkey: &[u8; 32], digest: &[u8; msg!( "Invalid Ix: data: {:?}, len: {:?}", ix.data.len(), - 16 + 64 + 32 + digest.len() + 16 + 64 + 32 + N ); return Err(ErrorCode::SigVerificationFailed.into()); } @@ -137,7 +141,7 @@ pub fn verify_ed25519_digest(ix: &Instruction, pubkey: &[u8; 32], digest: &[u8; // verify data is for digest and pubkey let ix_msg_data = &ix_data[112..]; - if ix_msg_data != digest || message_data_size != digest.len() as u16 { + if ix_msg_data != msg || message_data_size != N as u16 { return Err(ErrorCode::SigVerificationFailed.into()); } From 41b6991066a6ca72b6bfe0b3aa43f1eab3bb720b Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Wed, 20 Nov 2024 12:40:55 -0500 Subject: [PATCH 3/8] prettify --- sdk/src/driftClient.ts | 13 ++++++++----- sdk/tests/auctions/test.ts | 8 ++++++-- sdk/tests/decode/test.ts | 6 +++--- sdk/tests/dlob/helpers.ts | 6 ++++++ sdk/tests/subscriber/openbook.ts | 2 +- sdk/tests/user/helpers.ts | 2 ++ 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 4ba0a11df..40e17e696 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5786,17 +5786,20 @@ export class DriftClient { public signSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage ): Buffer { - const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage); + const takerOrderParamsMessage = + this.encodeSwiftOrderParamsMessage(orderParamsMessage); return this.signMessage(new TextEncoder().encode(takerOrderParamsMessage)); } public encodeSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage ): string { - return digest(this.program.coder.types.encode( - 'SwiftOrderParamsMessage', - orderParamsMessage - )).toString("hex"); + return digest( + this.program.coder.types.encode( + 'SwiftOrderParamsMessage', + orderParamsMessage + ) + ).toString('hex'); } public decodeSwiftOrderParamsMessage( diff --git a/sdk/tests/auctions/test.ts b/sdk/tests/auctions/test.ts index 294d39e67..3fb374cc3 100644 --- a/sdk/tests/auctions/test.ts +++ b/sdk/tests/auctions/test.ts @@ -1,6 +1,10 @@ -import { PRICE_PRECISION, BN, deriveOracleAuctionParams } from '../../src'; +import { + PRICE_PRECISION, + BN, + deriveOracleAuctionParams, + PositionDirection, +} from '../../src'; import { assert } from 'chai'; -import { PositionDirection } from '../../lib'; describe('Auction Tests', () => { it('deriveOracleAuctionParams', async () => { diff --git a/sdk/tests/decode/test.ts b/sdk/tests/decode/test.ts index a06d40f58..20f18bebd 100644 --- a/sdk/tests/decode/test.ts +++ b/sdk/tests/decode/test.ts @@ -1,8 +1,9 @@ import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor'; import driftIDL from '../../src/idl/drift.json'; import { Connection, Keypair } from '@solana/web3.js'; -import { Wallet } from '../../src'; import { + decodeUser, + Wallet, DRIFT_PROGRAM_ID, isSpotPositionAvailable, isVariant, @@ -10,8 +11,7 @@ import { PerpPosition, positionIsAvailable, SpotPosition, -} from '../../lib'; -import { decodeUser } from '../../lib/decode/user'; +} from '../../src'; import { assert } from 'chai'; import { userAccountBufferStrings } from './userAccountBufferStrings'; const sizeof = require('object-sizeof'); diff --git a/sdk/tests/dlob/helpers.ts b/sdk/tests/dlob/helpers.ts index f29ff8b59..41feffc44 100644 --- a/sdk/tests/dlob/helpers.ts +++ b/sdk/tests/dlob/helpers.ts @@ -163,6 +163,8 @@ export const mockPerpMarkets: Array = [ numberOfUsers: 0, marginRatioInitial: 2000, marginRatioMaintenance: 1000, + highLeverageMarginRatioInitial: 0, + highLeverageMarginRatioMaintenance: 0, nextFillRecordId: new BN(0), pnlPool: { scaledBalance: new BN(0), @@ -207,6 +209,8 @@ export const mockPerpMarkets: Array = [ numberOfUsers: 0, marginRatioInitial: 0, marginRatioMaintenance: 0, + highLeverageMarginRatioInitial: 0, + highLeverageMarginRatioMaintenance: 0, nextFillRecordId: new BN(0), pnlPool: { scaledBalance: new BN(0), @@ -249,6 +253,8 @@ export const mockPerpMarkets: Array = [ numberOfUsers: 0, marginRatioInitial: 0, marginRatioMaintenance: 0, + highLeverageMarginRatioInitial: 0, + highLeverageMarginRatioMaintenance: 0, nextFillRecordId: new BN(0), pnlPool: { scaledBalance: new BN(0), diff --git a/sdk/tests/subscriber/openbook.ts b/sdk/tests/subscriber/openbook.ts index 19dec92c0..a8c9e56b7 100644 --- a/sdk/tests/subscriber/openbook.ts +++ b/sdk/tests/subscriber/openbook.ts @@ -1,4 +1,4 @@ -import { OpenbookV2Subscriber, PRICE_PRECISION } from '../../lib'; +import { OpenbookV2Subscriber, PRICE_PRECISION } from '../../src'; import { Connection, PublicKey } from '@solana/web3.js'; describe('openbook v2 subscriber', function () { diff --git a/sdk/tests/user/helpers.ts b/sdk/tests/user/helpers.ts index ae2e81b10..31c41cda0 100644 --- a/sdk/tests/user/helpers.ts +++ b/sdk/tests/user/helpers.ts @@ -11,6 +11,7 @@ import { OrderTriggerCondition, UserAccount, ZERO, + MarginMode, } from '../../src'; import { mockPerpPosition } from '../dlob/helpers'; @@ -86,4 +87,5 @@ export const mockUserAccount: UserAccount = { openAuctions: 0, hasOpenAuction: false, lastFuelBonusUpdateTs: 0, + marginMode: MarginMode.DEFAULT, }; From 2db943806bc8b4e31b22032dda061fc4a6b42666 Mon Sep 17 00:00:00 2001 From: LukasDeco Date: Tue, 26 Nov 2024 14:44:20 -0700 Subject: [PATCH 4/8] feat: encodeSwiftOrderParamsMessage just return borsh buffer --- sdk/src/driftClient.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 40e17e696..e4ddd8d2f 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5788,18 +5788,16 @@ export class DriftClient { ): Buffer { const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage); - return this.signMessage(new TextEncoder().encode(takerOrderParamsMessage)); + return this.signMessage(new TextEncoder().encode(digest(takerOrderParamsMessage).toString('hex'))); } public encodeSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage - ): string { - return digest( - this.program.coder.types.encode( + ): Buffer { + return this.program.coder.types.encode( 'SwiftOrderParamsMessage', orderParamsMessage - ) - ).toString('hex'); + ); } public decodeSwiftOrderParamsMessage( From 539a39dda4549065c744da5ece18cd8086c816ba Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Fri, 29 Nov 2024 08:21:45 -0800 Subject: [PATCH 5/8] formatting --- programs/drift/src/instructions/keeper.rs | 4 ++-- sdk/src/driftClient.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index 6ea54f04b..a2e2410e2 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -63,8 +63,8 @@ use crate::state::user_map::{load_user_map, load_user_maps, UserMap, UserStatsMa use crate::validation::sig_verification::{extract_ed25519_ix_signature, verify_ed25519_msg}; use crate::validation::user::{validate_user_deletion, validate_user_is_idle}; use crate::{ - controller, digest_struct, digest_struct_hex, load, math, print_error, safe_decrement, OracleSource, - GOV_SPOT_MARKET_INDEX, MARGIN_PRECISION, + controller, digest_struct, digest_struct_hex, load, math, print_error, safe_decrement, + OracleSource, GOV_SPOT_MARKET_INDEX, MARGIN_PRECISION, }; use crate::{load_mut, QUOTE_PRECISION_U64}; use crate::{validate, QUOTE_PRECISION_I128}; diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index e4ddd8d2f..fc52a5d6a 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5788,16 +5788,18 @@ export class DriftClient { ): Buffer { const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage); - return this.signMessage(new TextEncoder().encode(digest(takerOrderParamsMessage).toString('hex'))); + return this.signMessage( + new TextEncoder().encode(digest(takerOrderParamsMessage).toString('hex')) + ); } public encodeSwiftOrderParamsMessage( orderParamsMessage: SwiftOrderParamsMessage ): Buffer { return this.program.coder.types.encode( - 'SwiftOrderParamsMessage', - orderParamsMessage - ); + 'SwiftOrderParamsMessage', + orderParamsMessage + ); } public decodeSwiftOrderParamsMessage( From d8ae7142c44dc3eae6d0f2f5d82ec1fb1e3b8bae Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Fri, 29 Nov 2024 08:50:00 -0800 Subject: [PATCH 6/8] fix borrow error --- programs/drift/src/instructions/keeper.rs | 3 ++- programs/drift/src/macros.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index a2e2410e2..2205daac6 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -604,11 +604,12 @@ pub fn place_swift_taker_order<'c: 'info, 'info>( )?; // Verify data from second verify ix + let digest_hex = digest_struct_hex!(taker_order_params_message); let ix: Instruction = load_instruction_at_checked(ix_idx as usize - 1, ix_sysvar)?; verify_ed25519_msg( &ix, &taker.authority.to_bytes(), - digest_struct_hex!(taker_order_params_message), + arrayref::array_ref!(digest_hex, 0, 64), )?; // Verify that sig from swift server corresponds to order message diff --git a/programs/drift/src/macros.rs b/programs/drift/src/macros.rs index 34bd89b45..f291041f2 100644 --- a/programs/drift/src/macros.rs +++ b/programs/drift/src/macros.rs @@ -100,7 +100,7 @@ macro_rules! digest_struct { /// Calculate the hexified sha256 digest of anchor encoded `struct` #[macro_export] macro_rules! digest_struct_hex { - ($struct:expr) => { - arrayref::array_ref!(hex::encode(digest_struct!($struct)).as_bytes(), 0, 64) - }; + ($struct:expr) => {{ + hex::encode(digest_struct!($struct)).into_bytes() + }}; } From ec9eb64d4b7d5bf8cac74c26ed33303261509225 Mon Sep 17 00:00:00 2001 From: Lukas deConantsesznak Date: Fri, 29 Nov 2024 13:09:18 -0700 Subject: [PATCH 7/8] fix: update sdk for hex encoding swift taker msg --- sdk/src/driftClient.ts | 4 +++- tests/placeAndMakeSwiftPerpBankrun.ts | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index fc52a5d6a..da8725993 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5876,7 +5876,9 @@ export class DriftClient { Ed25519Program.createInstructionWithPublicKey({ publicKey: takerInfo.takerUserAccount.authority.toBytes(), signature: Uint8Array.from(swiftOrderParamsSignature), - message: Uint8Array.from(digest(encodedSwiftOrderParamsMessage)), + message: new TextEncoder().encode( + digest(encodedSwiftOrderParamsMessage).toString('hex') + ), }); const placeTakerSwiftPerpOrderIx = diff --git a/tests/placeAndMakeSwiftPerpBankrun.ts b/tests/placeAndMakeSwiftPerpBankrun.ts index 982d78aa8..96dbb158c 100644 --- a/tests/placeAndMakeSwiftPerpBankrun.ts +++ b/tests/placeAndMakeSwiftPerpBankrun.ts @@ -32,6 +32,7 @@ import { ANCHOR_TEST_SWIFT_ID, SwiftOrderRecord, getSwiftUserAccountPublicKey, + digest, } from '../sdk/src'; import { @@ -415,7 +416,9 @@ describe('place and make swift order', () => { swiftDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = swiftDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -534,7 +537,9 @@ describe('place and make swift order', () => { takerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = takerDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -613,7 +618,9 @@ describe('place and make swift order', () => { takerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = takerDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -788,7 +795,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); From c168c870642b67ede97517422426efe8574c62f8 Mon Sep 17 00:00:00 2001 From: Lukas deConantsesznak Date: Sat, 30 Nov 2024 00:08:03 -0700 Subject: [PATCH 8/8] fix: maker order swift encoding add hex in tests --- tests/placeAndMakeSwiftPerp.ts | 20 +++++++++++++++----- tests/placeAndMakeSwiftPerpBankrun.ts | 8 ++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/placeAndMakeSwiftPerp.ts b/tests/placeAndMakeSwiftPerp.ts index 4d064a3c5..6816b4603 100644 --- a/tests/placeAndMakeSwiftPerp.ts +++ b/tests/placeAndMakeSwiftPerp.ts @@ -263,7 +263,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(digest(encodedSwiftServerMessage)), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -394,7 +396,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(digest(encodedSwiftServerMessage)), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -512,7 +516,9 @@ describe('place and make swift order', () => { takerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = takerDriftClient.signMessage( - Uint8Array.from(digest(encodedSwiftServerMessage)) + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ) ); try { @@ -632,7 +638,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(digest(encodedSwiftServerMessage)), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -663,7 +671,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage2); const swiftSignature2 = makerDriftClient.signMessage( - Uint8Array.from(digest(encodedSwiftServerMessage2)), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); diff --git a/tests/placeAndMakeSwiftPerpBankrun.ts b/tests/placeAndMakeSwiftPerpBankrun.ts index 96dbb158c..ce53cf5f9 100644 --- a/tests/placeAndMakeSwiftPerpBankrun.ts +++ b/tests/placeAndMakeSwiftPerpBankrun.ts @@ -245,7 +245,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair ); @@ -718,7 +720,9 @@ describe('place and make swift order', () => { makerDriftClient.encodeSwiftServerMessage(swiftServerMessage); const swiftSignature = makerDriftClient.signMessage( - Uint8Array.from(encodedSwiftServerMessage), + new TextEncoder().encode( + digest(encodedSwiftServerMessage).toString('hex') + ), swiftKeypair );