Auth Operation

The following is a example of Space operation:

/*
 * @Description: js-sdk for auth
 * @Autor: cess lab
 */
const { Authorize, InitAPI, testnetConfig, wellKnownAcct } = require("cess-js-sdk");
function getDataIfOk(result) {
  return result.msg === "ok" ? result.data : result;
}

async function main() {
  const { api, keyring } = await InitAPI(testnetConfig);
  const { mnemonic, addr, gatewayAddr } = wellKnownAcct;

  const oss = new Authorize(api, keyring);

  console.log("query authorityList:");
  let result = await oss.authorityList(addr);
  console.log(result.data, "\n");

  console.log("authorize:");
  result = await oss.authorize(mnemonic, gatewayAddr);
  console.log(getDataIfOk(result), "\n");

  console.log("query authorityList:");
  result = await oss.authorityList(addr);
  console.log(getDataIfOk(result), "\n");

  console.log("cancelAuthorize:");
  result = await oss.cancelAuthorize(mnemonic, gatewayAddr);
  console.log(getDataIfOk(result), "\n");

  console.log("query authorityList:");
  result = await oss.authorityList(addr);
  console.log(getDataIfOk(result));

  // console.log("authorize:");
  await oss.authorize(mnemonic, gatewayAddr);
  // console.log(getDataIfOk(result), "\n");
}

main()
  .catch(console.error)
  .finally(() => process.exit());

Last updated