Skip to content

Commit

Permalink
feature/support_protobuf_txs_3
Browse files Browse the repository at this point in the history
  • Loading branch information
nazhmik committed Jul 30, 2020
1 parent 8a60dde commit 0e64999
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 102 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 3 additions & 26 deletions src/adapters/LedgerAdapter.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -86,29 +84,8 @@ export class LedgerAdapter extends Adapter {
return Promise.reject('No private key');
}

public getSignVersions(): Record<SIGN_TYPE, Array<number>> {
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() {
Expand Down
28 changes: 3 additions & 25 deletions src/adapters/PrivateKeyAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,29 +30,8 @@ export class PrivateKeyAdapter extends Adapter {
this._isDestroyed = false;
}

public getSignVersions(): Record<SIGN_TYPE, Array<number>> {
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;
}


Expand Down
28 changes: 3 additions & 25 deletions src/adapters/SeedAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,29 +67,8 @@ export class SeedAdapter extends Adapter {
this._isDestroyed = false;
}

public getSignVersions(): Record<SIGN_TYPE, Array<number>> {
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<string> {
Expand Down
27 changes: 2 additions & 25 deletions src/adapters/WavesKeeperAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,3 +26,27 @@ export const adapterList = [
WavesKeeperAdapter,
PrivateKeyAdapter
];


export const TX_VERSIONS: Record<SIGN_TYPE, Array<number>> = {
[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]
};

0 comments on commit 0e64999

Please sign in to comment.