How to use @0xcert/utils - 10 common examples

To help you get started, we’ve selected a few @0xcert/utils 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 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
export function createSignatureTuple(claim: string[] | string) {
  if (typeof claim === 'string') {
    const [kind, signature] = claim.split(':');
    const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
    const signatureData = {
      r: signature.substr(0, 66),
      s: `0x${signature.substr(66, 64)}`,
      v: parseInt(`0x${signature.substr(130, 2)}`),
      k,
    };

    if (signatureData.v < 27) {
      signatureData.v = signatureData.v + 27;
    }
    return toTuple(signatureData);
  } else {
    const signatures = [];
    claim.forEach((c) => {
      const [kind, signature] = c.split(':');
      const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
      const signatureData = {
        r: signature.substr(0, 66),
        s: `0x${signature.substr(66, 64)}`,
        v: parseInt(`0x${signature.substr(130, 2)}`),
        k,
      };

      if (signatureData.v < 27) {
        signatureData.v = signatureData.v + 27;
      }
      signatures.push(signatureData);
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / asset-ledger-deploy-order.ts View on Github external
export function createSignatureTuple(claim: string) {
  const [kind, signature] = claim.split(':');
  const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;

  const signatureData = {
    r: signature.substr(0, 66),
    s: `0x${signature.substr(66, 64)}`,
    v: parseInt(`0x${signature.substr(130, 2)}`),
    k,
  };

  if (signatureData.v < 27) {
    signatureData.v = signatureData.v + 27;
  }

  return toTuple(signatureData);
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
claim.forEach((c) => {
      const [kind, signature] = c.split(':');
      const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
      const signatureData = {
        r: signature.substr(0, 66),
        s: `0x${signature.substr(66, 64)}`,
        v: parseInt(`0x${signature.substr(130, 2)}`),
        k,
      };

      if (signatureData.v < 27) {
        signatureData.v = signatureData.v + 27;
      }
      signatures.push(signatureData);
    });
    return toTuple(signatures);
  }
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / value-ledger-deploy-order.ts View on Github external
export function createSignatureTuple(claim: string) {
  const [kind, signature] = claim.split(':');
  const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;

  const signatureData = {
    r: signature.substr(0, 66),
    s: `0x${signature.substr(66, 64)}`,
    v: parseInt(`0x${signature.substr(130, 2)}`),
    k,
  };

  if (signatureData.v < 27) {
    signatureData.v = signatureData.v + 27;
  }

  return toTuple(signatureData);
}
github 0xcert / framework / packages / 0xcert-ethereum-deploy-gateway / src / lib / deploy.ts View on Github external
export function createSignatureTuple(claim: string) {
  const [kind, signature] = claim.split(':');
  const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;

  const signatureData = {
    r: signature.substr(0, 66),
    s: `0x${signature.substr(66, 64)}`,
    v: parseInt(`0x${signature.substr(130, 2)}`),
    k,
  };

  if (signatureData.v < 27) {
    signatureData.v = signatureData.v + 27;
  }

  return toTuple(signatureData);
}
github 0xcert / framework / packages / 0xcert-client / src / core / client.ts View on Github external
public async init() {
    let msg = 'test';
    if (this.provider.signMethod === SignMethod.ETH_SIGN) {
      msg = await sha(256, msg);
    }

    const signature = await this.provider.sign(`0x${msg}`);
    const signatureType = this.provider.signMethod;
    this.authentication = `${signatureType}:${signature}`;

    let data = null;
    try {
      const accountData = await clientFetch(`${this.apiUrl}/account`, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': this.authentication,
        },
      });
      data = accountData.data;
github 0xcert / framework / packages / 0xcert-ethereum-deploy-gateway / src / lib / deploy.ts View on Github external
deploy.assetLedgerData.schemaId.substr(2),
      capabilities,
      deploy.assetLedgerData.owner.substr(2),
    ].join('')),
  );

  const transferData = keccak256(
    hexToBytes([
      '0x',
      deploy.tokenTransferData.ledgerId.substr(2),
      deploy.tokenTransferData.receiverId.substr(2),
      getValue(deploy.tokenTransferData.value).substr(2),
    ].join('')),
  );

  return keccak256(
    hexToBytes([
      '0x',
      gateway.id.substr(2),
      deploy.makerId.substr(2),
      deploy.takerId.substr(2),
      xcertData.substr(2),
      transferData.substr(2),
      leftPad(toInteger(deploy.seed), 64, '0', false),
      leftPad(toSeconds(deploy.expiration), 64, '0', false),
    ].join('')),
  );
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
export function createOrderHash(gateway: Gateway, order: ActionsOrder) {
  let actionsHash = '0x0000000000000000000000000000000000000000000000000000000000000000';
  for (const action of order.actions) {
    actionsHash = keccak256(
      hexToBytes([
        '0x',
        actionsHash.substr(2),
        `0000000${getActionProxy(gateway, action)}`,
        action.ledgerId.substr(2),
        getActionParams(action, order.signers).substr(2),
      ].join('')),
    );
  }

  return keccak256(
    hexToBytes([
      '0x',
      gateway.config.actionsOrderId.substr(2),
      parseAddresses(order.signers),
      actionsHash.substr(2),
      leftPad(toInteger(order.seed), 64, '0', false),
      leftPad(toSeconds(order.expiration), 64, '0', false),
    ].join('')),
  );
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
export function createOrderHash(gateway: Gateway, order: ActionsOrder) {
  let actionsHash = '0x0000000000000000000000000000000000000000000000000000000000000000';
  for (const action of order.actions) {
    actionsHash = keccak256(
      hexToBytes([
        '0x',
        actionsHash.substr(2),
        `0000000${getActionProxy(gateway, action)}`,
        action.ledgerId.substr(2),
        getActionParams(action, order.signers).substr(2),
      ].join('')),
    );
  }

  return keccak256(
    hexToBytes([
      '0x',
      gateway.config.actionsOrderId.substr(2),
      parseAddresses(order.signers),
      actionsHash.substr(2),
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / asset-ledger-deploy-order.ts View on Github external
order.assetLedgerData.schemaId,
      capabilities,
      order.assetLedgerData.ownerId.substr(2),
    ].join('')),
  );

  const transferData = keccak256(
    hexToBytes([
      '0x',
      order.tokenTransferData.ledgerId.substr(2),
      order.tokenTransferData.receiverId.substr(2),
      getValue(order.tokenTransferData.value).substr(2),
    ].join('')),
  );

  return keccak256(
    hexToBytes([
      '0x',
      gateway.config.assetLedgerDeployOrderId.substr(2),
      order.makerId.substr(2),
      order.takerId.substr(2),
      xcertData.substr(2),
      transferData.substr(2),
      leftPad(toInteger(order.seed), 64, '0', false),
      leftPad(toSeconds(order.expiration), 64, '0', false),
    ].join('')),
  );
}

@0xcert/utils

General utility module with common helper functions.

MIT
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis