diff --git a/CHANGELOG.md b/CHANGELOG.md index ee05dd4d..bd552dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ All notable changes to this project will be documented in this file. See [standa ### [3.3.14](https://github.com/nash-io/nash-protocol/compare/v3.3.11...v3.3.14) (2020-11-24) +### [3.3.21](https://github.com/nash-io/nash-protocol/compare/v3.3.11...v3.3.21) (2020-12-16) + ### [3.3.11](https://github.com/nash-io/nash-protocol/compare/v3.4.7...v3.3.11) (2020-08-11) ### [3.3.7](https://github.com/nash-io/nash-protocol/compare/v3.3.5...v3.3.7) (2020-07-16) 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 7a408d2a..698814e0 100644 --- a/src/signPayload/signPayload.ts +++ b/src/signPayload/signPayload.ts @@ -138,7 +138,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') } @@ -212,7 +212,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') }