From 0e64999952f44ff343988a635728b82496a53af6 Mon Sep 17 00:00:00 2001 From: nazhmik Date: Thu, 30 Jul 2020 20:02:57 +0300 Subject: [PATCH] feature/support_protobuf_txs_3 --- package.json | 2 +- src/adapters/LedgerAdapter.ts | 29 +++-------------------------- src/adapters/PrivateKeyAdapter.ts | 28 +++------------------------- src/adapters/SeedAdapter.ts | 28 +++------------------------- src/adapters/WavesKeeperAdapter.ts | 27 ++------------------------- src/config.ts | 25 +++++++++++++++++++++++++ 6 files changed, 37 insertions(+), 102 deletions(-) diff --git a/package.json b/package.json index cb82471..dd56efa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@waves/signature-adapter", - "version": "5.12.0-beta.1", + "version": "5.12.0-beta.2", "types": "dist/index.d.ts", "main": "dist/index.js", "license": "MIT", diff --git a/src/adapters/LedgerAdapter.ts b/src/adapters/LedgerAdapter.ts index ef08620..dfe828a 100644 --- a/src/adapters/LedgerAdapter.ts +++ b/src/adapters/LedgerAdapter.ts @@ -1,8 +1,6 @@ import { Adapter } from './Adapter'; -import { AdapterType } from '../config'; +import { AdapterType, TX_VERSIONS } from '../config'; import { WavesLedger } from '@waves/ledger'; -import { SIGN_TYPE } from '../prepareTx'; - export class LedgerAdapter extends Adapter { @@ -86,29 +84,8 @@ export class LedgerAdapter extends Adapter { return Promise.reject('No private key'); } - 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] - }; + public getSignVersions() { + return TX_VERSIONS; } protected _isMyLedger() { diff --git a/src/adapters/PrivateKeyAdapter.ts b/src/adapters/PrivateKeyAdapter.ts index d694579..24b694c 100644 --- a/src/adapters/PrivateKeyAdapter.ts +++ b/src/adapters/PrivateKeyAdapter.ts @@ -1,7 +1,6 @@ import { Adapter, IPrivateKeyUser, IUser } from './Adapter'; -import { AdapterType } from '../config'; +import { AdapterType, TX_VERSIONS } from '../config'; import { seedUtils, libs } from '@waves/waves-transactions'; -import { SIGN_TYPE } from '../prepareTx'; const publicKey = libs.crypto.publicKey; const address = libs.crypto.address; @@ -31,29 +30,8 @@ export class PrivateKeyAdapter extends Adapter { this._isDestroyed = false; } - 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]: [0, 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], - }; + public getSignVersions() { + return TX_VERSIONS; } diff --git a/src/adapters/SeedAdapter.ts b/src/adapters/SeedAdapter.ts index 8bff64c..2f366ba 100644 --- a/src/adapters/SeedAdapter.ts +++ b/src/adapters/SeedAdapter.ts @@ -1,7 +1,6 @@ import { Adapter, IUser, ISeedUser } from './Adapter'; -import { AdapterType } from '../config'; +import { AdapterType, TX_VERSIONS } from '../config'; import { seedUtils, libs } from '@waves/waves-transactions'; -import { SIGN_TYPE } from '../prepareTx'; const Seed = seedUtils.Seed; const signWithPrivateKey = libs.crypto.signBytes; @@ -68,29 +67,8 @@ export class SeedAdapter extends Adapter { this._isDestroyed = false; } - 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] - }; + public getSignVersions() { + return TX_VERSIONS; } public getEncodedSeed(): Promise { diff --git a/src/adapters/WavesKeeperAdapter.ts b/src/adapters/WavesKeeperAdapter.ts index 4754a79..9126c90 100644 --- a/src/adapters/WavesKeeperAdapter.ts +++ b/src/adapters/WavesKeeperAdapter.ts @@ -1,32 +1,9 @@ import { Adapter } from './Adapter'; -import { AdapterType } from '../config'; +import { AdapterType, TX_VERSIONS } 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] -}; - export class WavesKeeperAdapter extends Adapter { public static type = AdapterType.WavesKeeper; @@ -37,7 +14,7 @@ export class WavesKeeperAdapter extends Adapter { private _needDestroy = false; private _address: string; private _pKey: string; - private static _txVersion: typeof DEFAULT_TX_VERSIONS = DEFAULT_TX_VERSIONS; + private static _txVersion = TX_VERSIONS; private static _getApiCb: () => IWavesKeeper; private static _api: IWavesKeeper; diff --git a/src/config.ts b/src/config.ts index 6263fac..a9e127b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,6 +2,7 @@ import { SeedAdapter } from './adapters/SeedAdapter'; import { LedgerAdapter } from './adapters/LedgerAdapter'; import { WavesKeeperAdapter } from './adapters'; import {PrivateKeyAdapter} from "./adapters/PrivateKeyAdapter"; +import { SIGN_TYPE } from '../src/prepareTx'; export const enum AdapterType { Seed = 'seed', @@ -25,3 +26,27 @@ export const adapterList = [ WavesKeeperAdapter, 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