diff --git a/src/payload/payload.ts b/src/payload/payload.ts index 4f4fdafd..509964d9 100644 --- a/src/payload/payload.ts +++ b/src/payload/payload.ts @@ -14,6 +14,9 @@ export interface SignedState extends SyncState { export const MovementTypeDeposit = 'DEPOSIT' export const MovementTypeWithdrawal = 'WITHDRAWAL' +// This is used for personal -> external +export const MovementTypeTransfer = 'TRANSFER' + export const BuyOrSellBuy = 'BUY' export const BuyOrSellSell = 'SELL' diff --git a/src/payload/signingPayloadID.ts b/src/payload/signingPayloadID.ts index c1d3d645..cfa74f75 100644 --- a/src/payload/signingPayloadID.ts +++ b/src/payload/signingPayloadID.ts @@ -1,4 +1,4 @@ -import { MovementTypeWithdrawal, MovementTypeDeposit } from './payload' +import { MovementTypeWithdrawal, MovementTypeDeposit, MovementTypeTransfer } from './payload' /** * IDs mapping Nash Matching Engine operations with handling strategies. @@ -101,15 +101,20 @@ export function isStateSigning(kind: SigningPayloadID): boolean { return kind === SigningPayloadID.signStatesPayload } -export function needBlockchainSignature(kind: SigningPayloadID): boolean { - return ( +export function needBlockchainSignature(kind: SigningPayloadID, payload): boolean { + if ( [ SigningPayloadID.placeLimitOrderPayload, SigningPayloadID.placeMarketOrderPayload, SigningPayloadID.placeStopLimitOrderPayload, - SigningPayloadID.placeStopMarketOrderPayload, - SigningPayloadID.addMovementPayload + SigningPayloadID.placeStopMarketOrderPayload ].indexOf(kind) > -1 + ) { + return true + } + + return ( + kind === SigningPayloadID.addMovementPayload && [MovementTypeDeposit, MovementTypeWithdrawal].includes(payload.type) ) } @@ -139,6 +144,9 @@ export function kindToOrderPrefix(kind: SigningPayloadID, payload?: any): string if (kind === SigningPayloadID.addMovementPayload && payload.type === MovementTypeWithdrawal) { return '03' } + if (kind === SigningPayloadID.addMovementPayload && payload.type === MovementTypeTransfer) { + return '' + } throw new Error(`invalid kind given ${kindToName(kind)}`) } diff --git a/src/signPayload/signPayload.ts b/src/signPayload/signPayload.ts index 1698e2f5..40d38fd2 100644 --- a/src/signPayload/signPayload.ts +++ b/src/signPayload/signPayload.ts @@ -134,7 +134,7 @@ export default function signPayload( pers: null }) - if (needBlockchainSignature(kind)) { + if (needBlockchainSignature(kind, payload)) { if (config === undefined) { throw new Error('blockchain signatures needs a Config object') } @@ -208,7 +208,7 @@ export async function preSignPayload( pers: null }) - if (needBlockchainSignature(kind)) { + if (needBlockchainSignature(kind, payload)) { if (config == null) { throw new Error('blockchain signatures needs a Config object') }