0.0.4 • Published 8 months ago

@sybil-center/zkc-preparator v0.0.4

Weekly downloads
-
License
(Apache-2.0 AND M...
Repository
github
Last release
8 months ago

ZK Credentials Preparator

Zero Knowledge Credentials (ZKC) Preparator is a library designed to assist developers in getting Zero Knowledge Credentials ready for use with Zero Knowledge Proof (ZKP) functions according to ZKC protocol (see ZK Credential: Preparation & Transformation Graphsections ).


API

Prepare ZK Credential

const zkCredential: ZKCredential = {
  isr: {
    id: { t: 1, k: "123456" }
  },
  sch: 1,
  isd: new Date().getTime(),
  exd: new Date().getTime(),
  sbj: {
    id: { k: "2345678", t: 2, },
    eth: "0x2...3",
    alias: "Test",
  }
};

const transSchema: TransCredSchema = {
  isr: {
    id: {
      t: ["uint32-bytes", "bytes-uint32", "uint32-boolean"],
      k: ["utf8-bytes"]
    },
  },
  sch: ["uint32-bytes", "bytes-base16"],
  isd: ["uint64-bytes", "bytes-base32"],
  exd: ["uint64-bytes", "bytes-utf8"],
  sbj: {
    id: {
      t: ["uint32-bytes"],
      k: ["utf8-bytes", "bytes-base16"]
    },
    alias: ["ascii-bytes", "bytes-uint128"],
    eth: ["utf8-bytes", "bytes-uint256"]
  }
};

const preparator = new Preparator();
const [
  isr_id_t, // boolean type
  isr_id_k, // Uint8Array
  sch,      // string as base16
  isd,      // string as base32
  exd,      // string as utf8
  sbj_id_t, // Uint8Array
  sbj_id_k, // string as base16
  alias,    // bigint
  eth       // bigint
] = preparator.prepare(zkCredential, transSchema);

Extend transformation graph

const preparator = new Preparator();
preparator.extendGraph([{ // extend transformation nodes
  name: "newNode",
  isType: (value: any) => value === "hello ZKCredentials"
}], [{ // extend transformation links
  inputType: "bytes",
  outputType: "bytes",
  name: "bytes.reverse",
  transform: (bytes: Uint8Array) => bytes.reverse()
}]);

Match between Transformation Graph types (nodes) and JS types

NameDescriptionJS Types
utf8UTF-8 encoded string, according to https://datatracker.ietf.org/doc/html/rfc3629string
base64Base64 encoded string, according to https://datatracker.ietf.org/doc/html/rfc3629string
base32Base32 encoded string, according to https://datatracker.ietf.org/doc/html/rfc3629string
base16Base16 encoded string, according to https://datatracker.ietf.org/doc/html/rfc3629string
base64urlBase64url encoded string, according to https://datatracker.ietf.org/doc/html/rfc7515#appendix-Cstring
base58Base58 encoded string, according to https://en.bitcoin.it/wiki/Base58Check_encodingstring
asciiACSII encoded string, according to https://datatracker.ietf.org/doc/html/rfc20string
int16Integer 16 bits sizenumber or bigint as input type for link, only bigint as output type
int32Integer 32 bits sizenumber or bigint as input type for link, only bigint as output type
int64Integer 64 bits sizenumber or bigint as input type for link, only bigint as output type
int128Integer 128 bits sizenumber or bigint as input type for link, only bigint as output type
int256Integer 256 bits sizenumber or bigint as input type for link, only bigint as output type
uint16Unsigned integer 16 bits sizenumber or bigint as input type for link, only bigint as output type
uint32Unsigned integer 32 bits sizenumber or bigint as input type for link, only bigint as output type
uint64Unsigned integer 64 bits sizenumber or bigint as input type for link, only bigint as output type
uint128Unsigned integer 128 bits sizenumber or bigint as input type for link, only bigint as output type
uint256Unsigned integer 256 bits sizenumber or bigint as input type for link, only bigint as output type
uintUnsigned integer withoout limitsnumber or bigint as input type for link, only bigint as output type
float32Float according to IEEE 754number
booleanBooleanboolean
bytesbytes arrayUint8Array