How to use the @arcblock/did.toDid 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 / authenticator / agent.js View on Github external
pathname = '',
    extraParams = {},
  }) {
    this._verifyClaims(verifiableClaims);
    this._verifyAuthorizer(authorizer);
    this._validateAppInfo(appInfo, { address: authorizer.did });

    const claimsInfo = await this.genRequestedClaims({ claims, context, extraParams });
    const chainInfoParams = Object.assign({}, context, extraParams);
    // FIXME: this maybe buggy if user provided multiple claims
    const tmp = claimsInfo.find(x => this.getChainInfo(chainInfoParams, x.chainInfo || {}));

    const payload = {
      action: 'responseAuth',
      appInfo,
      iss: toDid(authorizer.did),
      agentDid: toDid(this.wallet.address),
      chainInfo: this.getChainInfo(chainInfoParams, tmp ? tmp.chainInfo : undefined),
      verifiableClaims,
      requestedClaims: claimsInfo.map(x => {
        delete x.chainInfo;
        return x;
      }),
      url: `${this.baseUrl}${pathname}?${qs.stringify(Object.assign({ [this.tokenKey]: token }, extraParams))}`,
    };

    const signed = {
      appPk: toBase58(authorizer.pk),
      agentPk: this.appPk,
      authInfo: Jwt.sign(this.wallet.address, this.wallet.sk, payload),
    };
github ArcBlock / forge-js / did / did-auth / lib / authenticator / agent.js View on Github external
extraParams = {},
  }) {
    this._verifyClaims(verifiableClaims);
    this._verifyAuthorizer(authorizer);
    this._validateAppInfo(appInfo, { address: authorizer.did });

    const claimsInfo = await this.genRequestedClaims({ claims, context, extraParams });
    const chainInfoParams = Object.assign({}, context, extraParams);
    // FIXME: this maybe buggy if user provided multiple claims
    const tmp = claimsInfo.find(x => this.getChainInfo(chainInfoParams, x.chainInfo || {}));

    const payload = {
      action: 'responseAuth',
      appInfo,
      iss: toDid(authorizer.did),
      agentDid: toDid(this.wallet.address),
      chainInfo: this.getChainInfo(chainInfoParams, tmp ? tmp.chainInfo : undefined),
      verifiableClaims,
      requestedClaims: claimsInfo.map(x => {
        delete x.chainInfo;
        return x;
      }),
      url: `${this.baseUrl}${pathname}?${qs.stringify(Object.assign({ [this.tokenKey]: token }, extraParams))}`,
    };

    const signed = {
      appPk: toBase58(authorizer.pk),
      agentPk: this.appPk,
      authInfo: Jwt.sign(this.wallet.address, this.wallet.sk, payload),
    };

    debug('responseAuth.sign', { context, extraParams, payload, signed });
github ArcBlock / forge-js / did / did-auth / lib / jwt.js View on Github external
},
    [types.KeyType.ED25519]: {
      alg: 'Ed25519',
      type: 'JWT',
    },
  };

  // make header
  const header = headers[type.pk];
  const headerB64 = toBase64(stringify(header));

  // make body
  const now = Math.floor(Date.now() / 1000);
  let body = Object.assign(
    {
      iss: toDid(signer),
      iat: now,
      nbf: now,
      exp: now + 5 * 60,
      version: DID_AUTH_PROTOCOL_VERSION,
    },
    payload || {}
  );
  // remove empty keys
  body = Object.keys(body)
    .filter(x => {
      if (typeof body[x] === 'undefined' || body[x] == null || body[x] === '') {
        return false;
      }

      return true;
    })
github ArcBlock / forge-js / did / did-util / lib / index.js View on Github external
function toStakeDid(sender, receiver) {
  toDid(toStakeAddress(sender, receiver));
}
github ArcBlock / forge-js / did / did-util / lib / index.js View on Github external
function toItxDid(itx, type) {
  return toDid(toItxAddress(itx, type));
}
github ArcBlock / forge-js / did / did-auth / lib / authenticator / app.js View on Github external
sign(payload) {
    const { pk, sk, address } = this.wallet;
    return {
      appPk: toBase58(pk),
      appInfo: JWT.sign(toDid(address), sk, payload),
    };
  }
github ArcBlock / forge-js / did / did-util / lib / index.js View on Github external
function toAssetDid(itx) {
  return toDid(toAssetAddress(itx));
}