How to use the @arcblock/did-util.toDelegateAddress function in @arcblock/did-util

To help you get started, we’ve selected a few @arcblock/did-util 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 ArcBlock / forge-js / forge / client-extension / lib / index.js View on Github external
client.delegate = async ({ from, to, privileges }, extra) => {
    let ops = Array.isArray(privileges) ? privileges : [privileges];
    ops = ops.map(x => {
      if (x.typeUrl && Array.isArray(x.rules)) {
        return x;
      }

      return { typeUrl: x.typeUrl, rules: [] };
    });

    const txTypes = Object.values(typeUrls).filter(x => x.startsWith('fg:t:'));
    if (ops.some(x => txTypes.includes(x.typeUrl) === false)) {
      throw new Error('Invalid type url provided for delegation');
    }

    const address = toDelegateAddress(from.toAddress(), to.toAddress());
    const hash = await client.sendDelegateTx(
      {
        tx: {
          itx: {
            address,
            to: to.toAddress(),
            ops,
          },
        },
        wallet: from,
      },
      extra
    );

    return [hash, address];
  };

@arcblock/did-util

Helper function to calculate did

Apache-2.0
Latest version published 1 day ago

Package Health Score

63 / 100
Full package analysis