How to use the @requestnetwork/types.IdentityTypes.TYPE function in @requestnetwork/types

To help you get started, we’ve selected a few @requestnetwork/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / usage-examples / src / request-logic-clear-request.ts View on Github external
(async (): Promise => {
  // Data access setup
  const dataAccess = new DataAccess(new MockStorage());
  await dataAccess.initialize();

  // A transaction manager, for example @requestnetwork/transaction-manager
  const transactionManager: TransactionTypes.ITransactionManager = new TransactionManager(
    dataAccess,
  );

  const requestLogic = new RequestLogic(transactionManager, signatureProvider);

  const signerIdentity = {
    type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
    value: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
  };

  // optionally, compute the request ID before actually creating it.
  const requestId = await requestLogic.computeRequestId(createParams, signerIdentity);
  console.log(`The request will be created with ID ${requestId}`);

  const { result } = await requestLogic.createRequest(createParams, signerIdentity);

  return result;
})()
  .then(request => {
github RequestNetwork / requestNetwork / packages / prototype-estimator / src / size.ts View on Github external
};
const signerIdentity: IdentityTypes.IIdentity = {
  type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
  value: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
};

const requestCreationHash: RequestLogicTypes.ICreateParameters = {
  currency: {
    network: 'mainnet',
    type: RequestLogicTypes.CURRENCY.ETH,
    value: 'ETH',
  },
  expectedAmount: '100000000000',
  payee: signerIdentity,
  payer: {
    type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
    value: '0x740fc87Bd3f41d07d23A01DEc90623eBC5fed9D6',
  },
};

// Signature provider setup
const signatureProvider = new EthereumPrivateKeySignatureProvider(signatureInfo);

// Advanced logic setup
const advancedLogic = new AdvancedLogic();

/**
 * Sets up the test environment: instantiate the layers, including a mock storage
 *
 * @returns {Promise}
 */
async function setup(): Promise<{ mockStorage: MockStorage; requestLogic: RequestLogic }> {
github RequestNetwork / requestNetwork / packages / request-logic / specs / example / example.ts View on Github external
async function foo(): Promise {
  // Bob (the payee)
  const bobRaw = {
    identity: {
      type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
      value: '0xAf083f77F1fFd54218d91491AFD06c9296EaC3ce',
    },
    signatureParams: {
      method: SignatureTypes.METHOD.ECDSA,
      privateKey: '0x04674d2e53e0e14653487d7323cc5f0a7959c83067f5654cafe4094bde90fa8a',
    },
  };

  // Alice (the payer)
  const aliceRaw = {
    identity: {
      type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
      value: '0x740fc87Bd3f41d07d23A01DEc90623eBC5fed9D6',
    },
    signatureParams: {
      method: SignatureTypes.METHOD.ECDSA,
github RequestNetwork / requestNetwork / packages / request-logic / src / actions / create.ts View on Github external
}

  if (!Utils.amount.isValid(requestParameters.expectedAmount)) {
    throw new Error('expectedAmount must be a positive integer');
  }

  if (
    requestParameters.payee &&
    requestParameters.payee.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS
  ) {
    throw new Error('payee.type not supported');
  }

  if (
    requestParameters.payer &&
    requestParameters.payer.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS
  ) {
    throw new Error('payer.type not supported');
  }

  if (!requestParameters.timestamp) {
    requestParameters.timestamp = Utils.getCurrentTimestampInSecond();
  }

  // convert expectedAmount to string to have a consistent numbering
  requestParameters.expectedAmount = requestParameters.expectedAmount.toString();
  const version = Version.currentVersion;

  const unsignedAction: RequestLogicTypes.IUnsignedAction = {
    name: RequestLogicTypes.ACTION_NAME.CREATE,
    parameters: requestParameters,
    version,
github RequestNetwork / requestNetwork / packages / usage-examples / src / request-logic-encrypted-request.ts View on Github external
} from '@requestnetwork/types';

import MockStorage from './mock/mock-storage';

const createParams = {
  currency: {
    type: RequestLogicTypes.CURRENCY.ETH,
    value: 'ETH',
  },
  expectedAmount: '170000000000',
  payee: {
    type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
    value: '0xAf083f77F1fFd54218d91491AFD06c9296EaC3ce',
  },
  payer: {
    type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
    value: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
  },
  timestamp: 1544426030,
};

const payeeEncryptionParameters: EncryptionTypes.IEncryptionParameters = {
  key:
    '9008306d319755055226827c22f4b95552c799bae7af0e99780cf1b5500d9d1ecbdbcf6f27cdecc72c97fef3703c54b717bca613894212e0b2525cbb2d1161b9',
  method: EncryptionTypes.METHOD.ECIES,
};
const payeeDecryptionParameters: EncryptionTypes.IDecryptionParameters = {
  key: '0x0906ff14227cead2b25811514302d57706e7d5013fcc40eca5985b216baeb998',
  method: EncryptionTypes.METHOD.ECIES,
};

const payerEncryptionParameters: EncryptionTypes.IEncryptionParameters = {
github RequestNetwork / requestNetwork / packages / utils / src / encryption.ts View on Github external
function getIdentityFromEncryptionParams(
  encryptionParams: EncryptionTypes.IEncryptionParameters,
): IdentityTypes.IIdentity {
  if (encryptionParams.method === EncryptionTypes.METHOD.ECIES) {
    return {
      type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
      value: Crypto.EcUtils.getAddressFromPublicKey(encryptionParams.key),
    };
  }

  throw new Error('encryptionParams.method not supported');
}
github RequestNetwork / requestNetwork / packages / epk-decryption / src / ethereum-private-key-decryption-provider.ts View on Github external
return Array.from(this.decryptionParametersDictionary.keys(), address => ({
      type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
      value: address,
    }));
  }
github RequestNetwork / requestNetwork / packages / prototype-estimator / src / size.ts View on Github external
import { AdvancedLogic } from '@requestnetwork/advanced-logic';
import { DataAccess } from '@requestnetwork/data-access';
import { EthereumPrivateKeySignatureProvider } from '@requestnetwork/epk-signature';
import { RequestLogic } from '@requestnetwork/request-logic';
import { TransactionManager } from '@requestnetwork/transaction-manager';
import { IdentityTypes, RequestLogicTypes, SignatureTypes } from '@requestnetwork/types';
import MockStorage from './mock-storage';

const signatureInfo: SignatureTypes.ISignatureParameters = {
  method: SignatureTypes.METHOD.ECDSA,
  privateKey: '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',
};
const signerIdentity: IdentityTypes.IIdentity = {
  type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
  value: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
};

const requestCreationHash: RequestLogicTypes.ICreateParameters = {
  currency: {
    network: 'mainnet',
    type: RequestLogicTypes.CURRENCY.ETH,
    value: 'ETH',
  },
  expectedAmount: '100000000000',
  payee: signerIdentity,
  payer: {
    type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
    value: '0x740fc87Bd3f41d07d23A01DEc90623eBC5fed9D6',
  },
};
github RequestNetwork / requestNetwork / packages / request-logic / src / request.ts View on Github external
throw Error('request.currency is missing');
  }
  if (!request.requestId) {
    throw Error('request.requestId is missing');
  }
  if (!request.state) {
    throw Error('request.state is missing');
  }
  if (!request.creator) {
    throw Error('request.creator is missing');
  }

  if (!request.payee && !request.payer) {
    throw Error('request.payee and request.payer are missing');
  }
  if (request.creator.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS) {
    throw Error('request.creator.type not supported');
  }
  if (request.payee && request.payee.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS) {
    throw Error('request.payee.type not supported');
  }
  if (request.payer && request.payer.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS) {
    throw Error('request.payer.type not supported');
  }
  if (!Utils.amount.isValid(request.expectedAmount)) {
    throw Error('expectedAmount must be a positive integer');
  }
  return true;
}