How to use the @arcblock/did.isValid function in @arcblock/did

To help you get started, we’ve selected a few @arcblock/did 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 / did / did-auth / lib / handlers / util.js View on Github external
const steps = Array.isArray(claims) ? claims : [claims];
  if (steps.some(x => x.authPrincipal)) {
    // eslint-disable-next-line no-console
    console.warn('Setting authPrincipal in claims object is not recommended, and may break things');
  }

  // Prepend auth principal claim by default
  if (authPrincipal) {
    let target = '';
    let description = 'Please select authentication principal';
    let chainInfo;
    let targetType;
    let declareParams;

    if (typeof authPrincipal === 'string') {
      if (isValidDid(authPrincipal)) {
        // If auth principal is provided as a did
        target = authPrincipal;
      } else {
        // If auth principal is provided as a string
        description = authPrincipal;
      }
    }
    if (typeof authPrincipal === 'object') {
      target = get(authPrincipal, 'target', target);
      description = get(authPrincipal, 'description', description);
      targetType = get(authPrincipal, 'targetType', targetType);
      declareParams = get(authPrincipal, 'declareParams', declareParams);

      // If provided a chainInfo
      if (authPrincipal.chainInfo && authenticator._isValidChainInfo(authPrincipal.chainInfo)) {
        chainInfo = authPrincipal.chainInfo;
github ArcBlock / forge-js / did / did-auth / lib / jwt.js View on Github external
const sign = (signer, sk, payload = {}, doSign = true) => {
  if (isValid(signer) === false) {
    throw new Error('Cannot do sign with invalid signer');
  }

  const type = toTypeInfo(signer);
  const headers = {
    [types.KeyType.SECP256K1]: {
      alg: 'ES256K',
      type: 'JWT',
    },
    [types.KeyType.ED25519]: {
      alg: 'Ed25519',
      type: 'JWT',
    },
  };

  // make header
github ArcBlock / forge-js / forge / client-extension / lib / index.js View on Github external
client.finalizeConsumeAsset = ({ tx, address, delegator, wallet }, extra) => {
    if (isValidDID(address) === false) {
      throw new Error('Please provide valid asset address to consume');
    }

    return client.multiSignConsumeAssetTx(
      {
        tx,
        wallet,
        delegator,
        data: {
          typeUrl: 'fg:x:address',
          value: Uint8Array.from(Buffer.from(address)),
        },
      },
      extra
    );
  };