{"size": 1090, "ext": "js", "max_stars_repo_path": "wasm/packages/okapi/test/node.test.js", "max_stars_repo_name": "tmarkovski/okapi", "max_stars_repo_stars_event_min_datetime": "2021-05-11T07:54:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T17:56:48.000Z", "max_issues_repo_path": "wasm/packages/okapi/test/node.test.js", "max_issues_repo_name": "tmarkovski/okapi", "max_issues_repo_issues_event_min_datetime": "2021-05-06T12:22:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:59:58.000Z", "max_forks_repo_path": "wasm/packages/okapi/test/node.test.js", "max_forks_repo_name": "tmarkovski/okapi", "max_forks_repo_forks_event_min_datetime": "2021-06-04T00:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-13T00:08:13.000Z"}
{"max_stars_count": 9, "max_issues_count": 265, "max_forks_count": 5, "avg_line_length": 28.6842105263, "max_line_length": 108, "alphanum_fraction": 0.7174311927}
const test = require("ava");
const {
  DIDKey,
  GenerateKeyRequest,
  CreateOberonKeyRequest,
  CreateOberonTokenRequest,
  CreateOberonProofRequest,
  VerifyOberonProofRequest,
  KeyType,
  Oberon,
} = require("../lib/index.js");

test("generate bls key", async (t) => {
  var response = await DIDKey.generate(new GenerateKeyRequest().setKeyType(KeyType.KEY_TYPE_BLS12381G1G2));

  t.not(null, response);
  t.not(undefined, response);
});

test("create and verify oberon token", async (t) => {
  var key = await Oberon.createKey(new CreateOberonKeyRequest());
  var id = Buffer.from("me@example.com");
  var nonce = Buffer.from("123");

  var token = await Oberon.createToken(new CreateOberonTokenRequest().setData(id).setSk(key.getSk()));
  t.not(null, token);

  var proof = await Oberon.createProof(
    new CreateOberonProofRequest().setToken(token.getToken()).setData(id).setNonce(nonce)
  );

  var result = await Oberon.verifyProof(
    new VerifyOberonProofRequest().setData(id).setNonce(nonce).setProof(proof.getProof()).setPk(key.getPk())
  );

  t.true(result.getValid());
});
