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

To help you get started, we’ve selected a few @0xcert/scaffold 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-asset-ledger / src / core / ledger.ts View on Github external
public async revokeAbilities(accountId: string | OrderGatewayBase, abilities: AssetLedgerAbility[]): Promise {
    if (typeof accountId !== 'string') {
      accountId = await (accountId as any).getProxyAccountId(0); // OrderGatewayProxy.XCERT_CREATE
    }

    let allowSuperRevoke = false;
    if (abilities.indexOf(SuperAssetLedgerAbility.MANAGE_ABILITIES) !== -1) {
      allowSuperRevoke = true;
    }

    accountId = this._provider.encoder.normalizeAddress(accountId as string);

    let bitAbilities = bigNumberify(0);
    abilities.forEach((ability) => {
      bitAbilities = bitAbilities.add(ability);
    });

    return revokeAbilities(this, accountId, bitAbilities, allowSuperRevoke);
  }
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / value-ledger-deploy-order.ts View on Github external
export function normalizeOrderIds(order: ValueLedgerDeployOrder, provider: GenericProvider): ValueLedgerDeployOrder {
  order = JSON.parse(JSON.stringify(order));
  let dynamic = false;

  if (!order.takerId) {
    order.takerId = zeroAddress;
    dynamic = true;
  } else {
    order.takerId = provider.encoder.normalizeAddress(order.takerId);
  }
  order.makerId = provider.encoder.normalizeAddress(order.makerId);
  order.tokenTransferData.ledgerId = provider.encoder.normalizeAddress(order.tokenTransferData.ledgerId);

  if (!order.tokenTransferData.receiverId) {
    if (!dynamic) {
      throw new ProviderError(ProviderIssue.WRONG_INPUT, 'receiverId is not set.');
    }
    order.tokenTransferData.receiverId = zeroAddress;
  } else {
    order.tokenTransferData.receiverId = provider.encoder.normalizeAddress(order.tokenTransferData.receiverId);
  }
  order.valueLedgerData.ownerId = provider.encoder.normalizeAddress(order.valueLedgerData.ownerId);
  return order;
}
github 0xcert / framework / packages / 0xcert-ethereum-generic-provider / src / core / errors.ts View on Github external
export function parseError(error: any) {
  if (error instanceof ProviderError) {
    return error;
  } else if (Object.values(ProviderIssue).includes(error)) {
    return new ProviderError(error);
  } else {
    return new ProviderError(ProviderIssue.CONTRACT_ERROR, error);
  }
}
github 0xcert / framework / packages / 0xcert-ethereum-value-ledger / src / core / ledger.ts View on Github external
public async approveValue(value: string, accountId: string): Promise {
    accountId = this._provider.encoder.normalizeAddress(accountId as string);

    const approvedValue = await this.getApprovedValue(this.provider.accountId, accountId);
    if (!bigNumberify(value).isZero() && !bigNumberify(approvedValue).isZero()) {
      throw new ProviderError(ProviderIssue.ERC20_APPROVAL_RACE_CONDITION);
    }

    return approveAccount(this, accountId, value);
  }
github 0xcert / framework / packages / 0xcert-ethereum-generic-provider / src / core / errors.ts View on Github external
export function parseError(error: any) {
  if (error instanceof ProviderError) {
    return error;
  } else if (Object.values(ProviderIssue).includes(error)) {
    return new ProviderError(error);
  } else {
    return new ProviderError(ProviderIssue.CONTRACT_ERROR, error);
  }
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / asset-ledger-deploy-order.ts View on Github external
export function normalizeOrderIds(order: AssetLedgerDeployOrder, provider: GenericProvider): AssetLedgerDeployOrder {
  order = JSON.parse(JSON.stringify(order));
  let dynamic = false;

  if (!order.takerId) {
    order.takerId = zeroAddress;
    dynamic = true;
  } else {
    order.takerId = provider.encoder.normalizeAddress(order.takerId);
  }
  order.makerId = provider.encoder.normalizeAddress(order.makerId);
  order.tokenTransferData.ledgerId = provider.encoder.normalizeAddress(order.tokenTransferData.ledgerId);

  if (!order.tokenTransferData.receiverId) {
    if (!dynamic) {
      throw new ProviderError(ProviderIssue.WRONG_INPUT, 'receiverId is not set.');
    }
    order.tokenTransferData.receiverId = zeroAddress;
  } else {
    order.tokenTransferData.receiverId = provider.encoder.normalizeAddress(order.tokenTransferData.receiverId);
  }
  order.assetLedgerData.ownerId = provider.encoder.normalizeAddress(order.assetLedgerData.ownerId);
  return order;
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
    return ProxyId.TOKEN_TRANSFER;
  } else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
    return gateway.provider.unsafeRecipientIds.indexOf(action.ledgerId) === -1
      ? ProxyId.NFTOKEN_SAFE_TRANSFER
      : ProxyId.NFTOKEN_TRANSFER;
  } else if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
    return ProxyId.XCERT_CREATE;
  } else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
    return ProxyId.MANAGE_ABILITIES;
  } else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
    return ProxyId.XCERT_UPDATE;
  } else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
    return ProxyId.XCERT_BURN;
  } else {
    throw new ProviderError(ProviderIssue.WRONG_INPUT, 'Not implemented.');
  }
}
github 0xcert / framework / packages / 0xcert-ethereum-gateway / src / lib / actions-order.ts View on Github external
export function getActionParams(action: ActionsOrderAction, signers: string[]) {
  let params = '';
  const signerIndex = signers.indexOf(action['senderId']);
  if (signerIndex === -1) {
    throw new ProviderError(ProviderIssue.WRONG_INPUT, 'SenderId not a signer.');
  }
  if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
    params = rightPad(`0x${action['assetImprint']}`, 64);
    params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
    params += action['receiverId'].substr(2);
    params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
  } else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
    const bitAbilities = getBitfieldFromAbilities(action.abilities);
    params =  leftPad(bitAbilities, 64, '0', true);
    params += action['receiverId'].substr(2);
    params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
  } else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
    params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
    params += action['receiverId'].substr(2);
    params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
  } else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
github 0xcert / framework / packages / 0xcert-web3-context / src / core / context.ts View on Github external
protected getSignMethod(signMethod?: SignMethod) {
    if (signMethod === undefined) {
      signMethod = SignMethod.ETH_SIGN;
    }

    if ([0, 1, 2].indexOf(signMethod) === -1) {
      throw new ConnectorError(ConnectorIssue.SIGNATURE_UNKNOWN, `Unknown signature method ${signMethod}`);
    }

    return signMethod;
  }
github 0xcert / framework / packages / 0xcert-web3-context / src / core / context.ts View on Github external
protected async signData(data: string) {
    try {
      switch (this.signMethod) {
        case SignMethod.ETH_SIGN:
          return await this.web3.eth.sign(data, this.myId);
        case SignMethod.TREZOR:
          return '';
        case SignMethod.EIP712:
          return await this.web3.eth.sign(data, this.myId);
        default:
          return null;
      }
    }
    catch (error) {
      throw new ConnectorError(ConnectorIssue.SIGNATURE_FAILED, error);
    }
  }