How to use @0xcert/ethereum-generic-provider - 10 common examples

To help you get started, we’ve selected a few @0xcert/ethereum-generic-provider 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-order-gateway / src / mutations / perform.ts View on Github external
let functionSignature = '0x8b1d8335'; // perform
  if (order.takerId === zeroAddress) {
    functionSignature = '0x04aa2cb7'; // performAnyTaker
  }
  const recipeTuple = createRecipeTuple(gateway, order);
  const signatureTuple = createSignatureTuple(claim);
  const attrs = {
    from: gateway.provider.accountId,
    to: gateway.id,
    data: functionSignature + gateway.provider.encoder.encodeParameters(inputTypes, [recipeTuple, signatureTuple]).substr(2),
  };
  const res = await gateway.provider.post({
    method: 'eth_sendTransaction',
    params: [attrs],
  });
  return new Mutation(gateway.provider, res.result);
}
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-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-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,
        },
      });
github 0xcert / framework / packages / 0xcert-ethereum-metamask-provider / src / core / provider.ts View on Github external
protected async installEvents() {

    const networkVersion = await this.getNetworkVersion();
    if (networkVersion !== this._networkVersion) {
      this.emit(ProviderEvent.NETWORK_CHANGE, networkVersion, this._networkVersion);
      this._networkVersion = networkVersion;
    }

    this.accountId = await this.getAvailableAccounts().then((a) => a[0]);

    setTimeout(() => this.installEvents(), 1000);
  }
github 0xcert / framework / packages / 0xcert-ethereum-value-ledger / src / mutations / deploy.ts View on Github external
export default async function(provider: GenericProvider, { name, symbol, decimals, supply }: ValueLedgerDeployRecipe) {
  const contract = await fetchJson(provider.valueLedgerSource);
  const source = contract.TokenMock.evm.bytecode.object;
  const attrs = {
    from: provider.accountId,
    data: `0x${source}${provider.encoder.encodeParameters(inputTypes, [ name, symbol, decimals, supply]).substr(2)}`,
  };
  const res = await provider.post({
    method: 'eth_sendTransaction',
    params: [attrs],
  });
  return new Mutation(provider, res.result);
}
github 0xcert / framework / packages / 0xcert-ethereum-asset-ledger / src / mutations / deploy.ts View on Github external
export default async function(provider: GenericProvider, { name, symbol, uriPrefix, uriPostfix, schemaId, capabilities }: AssetLedgerDeployRecipe) {
  const contract = await fetchJson(provider.assetLedgerSource);
  const source = contract.XcertMock.evm.bytecode.object;
  const codes = (capabilities || []).map((c) => getInterfaceCode(c));
  const attrs = {
    from: provider.accountId,
    data: `0x${source}${provider.encoder.encodeParameters(inputTypes, [name, symbol, uriPrefix, uriPostfix, schemaId, codes]).substr(2)}`,
  };
  const res = await provider.post({
    method: 'eth_sendTransaction',
    params: [attrs],
  });
  return new Mutation(provider, res.result);
}
github 0xcert / framework / packages / 0xcert-ethereum-asset-ledger / src / mutations / approve-account.ts View on Github external
export default async function(ledger: AssetLedger, accountId: string, assetId: string) {
  const attrs = {
    from: ledger.provider.accountId,
    to: ledger.id,
    data: functionSignature + ledger.provider.encoder.encodeParameters(inputTypes, [accountId, assetId]).substr(2),
  };
  const res = await ledger.provider.post({
    method: 'eth_sendTransaction',
    params: [attrs],
  });
  return new Mutation(ledger.provider, res.result, ledger);
}