Skip to content

Commit

Permalink
feature/support_protobuf_txs: return sign versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nazhmik committed Jul 31, 2020
1 parent 55965b1 commit a865588
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 10 deletions.
31 changes: 27 additions & 4 deletions src/adapters/LedgerAdapter.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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<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],
[SIGN_TYPE.UPDATE_ASSET_INFO]: []
};
}

protected _isMyLedger() {
Expand Down
27 changes: 25 additions & 2 deletions src/adapters/PrivateKeyAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,7 +32,29 @@ export class PrivateKeyAdapter extends Adapter {
}

public getSignVersions() {
return TX_VERSIONS;
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]: []
};
}


Expand Down
27 changes: 25 additions & 2 deletions src/adapters/SeedAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,7 +69,29 @@ export class SeedAdapter extends Adapter {
}

public getSignVersions() {
return TX_VERSIONS;
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<string> {
Expand Down
28 changes: 26 additions & 2 deletions src/adapters/WavesKeeperAdapter.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit a865588

Please sign in to comment.