diff --git a/src/adapters/LedgerAdapter.ts b/src/adapters/LedgerAdapter.ts index dfe828a..f48fc79 100644 --- a/src/adapters/LedgerAdapter.ts +++ b/src/adapters/LedgerAdapter.ts @@ -1,6 +1,7 @@ import { Adapter } from './Adapter'; -import { AdapterType, TX_VERSIONS } from '../config'; +import { AdapterType } from '../config'; import { WavesLedger } from '@waves/ledger'; +import { SIGN_TYPE } from '../prepareTx/constants'; export class LedgerAdapter extends Adapter { @@ -83,9 +84,31 @@ export class LedgerAdapter extends Adapter { public getPrivateKey() { return Promise.reject('No private key'); } - - public getSignVersions() { - return TX_VERSIONS; + + public getSignVersions(): Record> { + return { + [SIGN_TYPE.AUTH]: [1], + [SIGN_TYPE.MATCHER_ORDERS]: [1], + [SIGN_TYPE.WAVES_CONFIRMATION]: [1], + [SIGN_TYPE.CREATE_ORDER]: [1, 2, 3], + [SIGN_TYPE.CANCEL_ORDER]: [1], + [SIGN_TYPE.COINOMAT_CONFIRMATION]: [1], + [SIGN_TYPE.ISSUE]: [2], + [SIGN_TYPE.TRANSFER]: [2], + [SIGN_TYPE.REISSUE]: [2], + [SIGN_TYPE.BURN]: [2], + [SIGN_TYPE.EXCHANGE]: [0,1,2], + [SIGN_TYPE.LEASE]: [2], + [SIGN_TYPE.CANCEL_LEASING]: [2], + [SIGN_TYPE.CREATE_ALIAS]: [2], + [SIGN_TYPE.MASS_TRANSFER]: [1], + [SIGN_TYPE.DATA]: [1], + [SIGN_TYPE.SET_SCRIPT]: [1], + [SIGN_TYPE.SPONSORSHIP]: [1], + [SIGN_TYPE.SET_ASSET_SCRIPT]: [1], + [SIGN_TYPE.SCRIPT_INVOCATION]: [1], + [SIGN_TYPE.UPDATE_ASSET_INFO]: [] + }; } protected _isMyLedger() { diff --git a/src/adapters/PrivateKeyAdapter.ts b/src/adapters/PrivateKeyAdapter.ts index 24b694c..7b1da4d 100644 --- a/src/adapters/PrivateKeyAdapter.ts +++ b/src/adapters/PrivateKeyAdapter.ts @@ -1,6 +1,7 @@ import { Adapter, IPrivateKeyUser, IUser } from './Adapter'; -import { AdapterType, TX_VERSIONS } from '../config'; +import { AdapterType } from '../config'; import { seedUtils, libs } from '@waves/waves-transactions'; +import { SIGN_TYPE } from '../prepareTx'; const publicKey = libs.crypto.publicKey; const address = libs.crypto.address; @@ -30,8 +31,30 @@ export class PrivateKeyAdapter extends Adapter { this._isDestroyed = false; } - public getSignVersions() { - return TX_VERSIONS; + public getSignVersions(): Record> { + return { + [SIGN_TYPE.AUTH]: [1], + [SIGN_TYPE.MATCHER_ORDERS]: [1], + [SIGN_TYPE.CREATE_ORDER]: [1, 2, 3], + [SIGN_TYPE.CANCEL_ORDER]: [0, 1], + [SIGN_TYPE.COINOMAT_CONFIRMATION]: [1], + [SIGN_TYPE.WAVES_CONFIRMATION]: [1], + [SIGN_TYPE.TRANSFER]: [2, 3], + [SIGN_TYPE.ISSUE]: [2, 3], + [SIGN_TYPE.REISSUE]: [2, 3], + [SIGN_TYPE.BURN]: [2, 3], + [SIGN_TYPE.EXCHANGE]: [0, 1, 2, 3], + [SIGN_TYPE.LEASE]: [2, 3], + [SIGN_TYPE.CANCEL_LEASING]: [2, 3], + [SIGN_TYPE.CREATE_ALIAS]: [2, 3], + [SIGN_TYPE.MASS_TRANSFER]: [1, 2], + [SIGN_TYPE.DATA]: [1, 2], + [SIGN_TYPE.SET_SCRIPT]: [1, 2], + [SIGN_TYPE.SPONSORSHIP]: [1, 2], + [SIGN_TYPE.SET_ASSET_SCRIPT]: [1, 2], + [SIGN_TYPE.SCRIPT_INVOCATION]: [1, 2], + [SIGN_TYPE.UPDATE_ASSET_INFO]: [] + }; } diff --git a/src/adapters/SeedAdapter.ts b/src/adapters/SeedAdapter.ts index 2f366ba..c7967f3 100644 --- a/src/adapters/SeedAdapter.ts +++ b/src/adapters/SeedAdapter.ts @@ -1,6 +1,7 @@ import { Adapter, IUser, ISeedUser } from './Adapter'; -import { AdapterType, TX_VERSIONS } from '../config'; +import { AdapterType } from '../config'; import { seedUtils, libs } from '@waves/waves-transactions'; +import { SIGN_TYPE } from '../prepareTx'; const Seed = seedUtils.Seed; const signWithPrivateKey = libs.crypto.signBytes; @@ -67,8 +68,30 @@ export class SeedAdapter extends Adapter { this._isDestroyed = false; } - public getSignVersions() { - return TX_VERSIONS; + public getSignVersions(): Record> { + return { + [SIGN_TYPE.AUTH]: [1], + [SIGN_TYPE.MATCHER_ORDERS]: [1], + [SIGN_TYPE.CREATE_ORDER]: [1, 2, 3], + [SIGN_TYPE.CANCEL_ORDER]: [0, 1], + [SIGN_TYPE.COINOMAT_CONFIRMATION]: [1], + [SIGN_TYPE.WAVES_CONFIRMATION]: [1], + [SIGN_TYPE.TRANSFER]: [2, 3], + [SIGN_TYPE.ISSUE]: [2, 3], + [SIGN_TYPE.REISSUE]: [2, 3], + [SIGN_TYPE.BURN]: [2, 3], + [SIGN_TYPE.EXCHANGE]: [0, 1, 2, 3], + [SIGN_TYPE.LEASE]: [2, 3], + [SIGN_TYPE.CANCEL_LEASING]: [2, 3], + [SIGN_TYPE.CREATE_ALIAS]: [2, 3], + [SIGN_TYPE.MASS_TRANSFER]: [1, 2], + [SIGN_TYPE.DATA]: [1, 2], + [SIGN_TYPE.SET_SCRIPT]: [1, 2], + [SIGN_TYPE.SPONSORSHIP]: [1, 2], + [SIGN_TYPE.SET_ASSET_SCRIPT]: [1, 2], + [SIGN_TYPE.SCRIPT_INVOCATION]: [1, 2], + [SIGN_TYPE.UPDATE_ASSET_INFO]: [] + }; } public getEncodedSeed(): Promise { diff --git a/src/adapters/WavesKeeperAdapter.ts b/src/adapters/WavesKeeperAdapter.ts index 9126c90..ef22f23 100644 --- a/src/adapters/WavesKeeperAdapter.ts +++ b/src/adapters/WavesKeeperAdapter.ts @@ -1,9 +1,33 @@ import { Adapter } from './Adapter'; -import { AdapterType, TX_VERSIONS } from '../config'; +import { AdapterType } from '../config'; import { SIGN_TYPE, TSignData } from '../prepareTx'; import { isValidAddress } from '../prepareTx/fieldValidator'; import equals = require('ramda/src/equals'); +const DEFAULT_TX_VERSIONS = { + [SIGN_TYPE.AUTH]: [1], + [SIGN_TYPE.MATCHER_ORDERS]: [1], + [SIGN_TYPE.CREATE_ORDER]: [1, 2, 3], + [SIGN_TYPE.CANCEL_ORDER]: [1], + [SIGN_TYPE.COINOMAT_CONFIRMATION]: [1], + [SIGN_TYPE.WAVES_CONFIRMATION]: [1], + [SIGN_TYPE.TRANSFER]: [2, 3], + [SIGN_TYPE.ISSUE]: [2, 3], + [SIGN_TYPE.REISSUE]: [2, 3], + [SIGN_TYPE.BURN]: [2, 3], + [SIGN_TYPE.EXCHANGE]: [0, 1, 2, 3], + [SIGN_TYPE.LEASE]: [2, 3], + [SIGN_TYPE.CANCEL_LEASING]: [2, 3], + [SIGN_TYPE.CREATE_ALIAS]: [2, 3], + [SIGN_TYPE.MASS_TRANSFER]: [1, 2], + [SIGN_TYPE.DATA]: [1, 2], + [SIGN_TYPE.SET_SCRIPT]: [1, 2], + [SIGN_TYPE.SPONSORSHIP]: [1, 2], + [SIGN_TYPE.SET_ASSET_SCRIPT]: [1, 2], + [SIGN_TYPE.SCRIPT_INVOCATION]: [1, 2], + [SIGN_TYPE.UPDATE_ASSET_INFO]: [] +}; + export class WavesKeeperAdapter extends Adapter { public static type = AdapterType.WavesKeeper; @@ -14,7 +38,7 @@ export class WavesKeeperAdapter extends Adapter { private _needDestroy = false; private _address: string; private _pKey: string; - private static _txVersion = TX_VERSIONS; + private static _txVersion: typeof DEFAULT_TX_VERSIONS = DEFAULT_TX_VERSIONS; private static _getApiCb: () => IWavesKeeper; private static _api: IWavesKeeper; diff --git a/src/config.ts b/src/config.ts index 50f9d9d..b13acbf 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,26 +27,3 @@ export const adapterList = [ PrivateKeyAdapter ]; - -export const TX_VERSIONS: Record> = { - [SIGN_TYPE.AUTH]: [1], - [SIGN_TYPE.MATCHER_ORDERS]: [1], - [SIGN_TYPE.CREATE_ORDER]: [1, 2, 3], - [SIGN_TYPE.CANCEL_ORDER]: [0, 1], - [SIGN_TYPE.COINOMAT_CONFIRMATION]: [1], - [SIGN_TYPE.WAVES_CONFIRMATION]: [1], - [SIGN_TYPE.TRANSFER]: [2, 3], - [SIGN_TYPE.ISSUE]: [2, 3], - [SIGN_TYPE.REISSUE]: [2, 3], - [SIGN_TYPE.BURN]: [2, 3], - [SIGN_TYPE.EXCHANGE]: [0, 1, 2, 3], - [SIGN_TYPE.LEASE]: [2, 3], - [SIGN_TYPE.CANCEL_LEASING]: [2, 3], - [SIGN_TYPE.CREATE_ALIAS]: [2, 3], - [SIGN_TYPE.MASS_TRANSFER]: [1, 2], - [SIGN_TYPE.DATA]: [1, 2], - [SIGN_TYPE.SET_SCRIPT]: [1, 2], - [SIGN_TYPE.SPONSORSHIP]: [1, 2], - [SIGN_TYPE.SET_ASSET_SCRIPT]: [1, 2], - [SIGN_TYPE.SCRIPT_INVOCATION]: [1, 2] -}; \ No newline at end of file