Getting Started

This tutorial will show you how to use the portablegabi library. It will take you approx. 30 minutes to work through. Before you dive in and try out the tutorial, you need to set up your environment.

To get started, you need to have the following dependencies installed:

  • node (any version starting with 10.19)
  • yarn

Set up a tutorial project

If you want to try out the examples inside this tutorial, create a new project and add Portablegabi as a dependency by using yarn add. If you have built and customized the Portablegabi repo on your own, just link it with yarn link.

mkdir portablegabi-rocks
cd portablegabi-rocks
yarn init -y
yarn add @kiltprotocol/portablegabi
# or if you have build and linked Portablegabi by yourself:
yarn link @kiltprotocol/portablegabi

Create an JavaScript file

touch index.js

and after adding some code from the examples, execute them with node

node index.js

Run the examples

Most of the Portablegabi functions are asynchronous (due to calling the WASM in a callback-fashion). Therefore, you need to wrap the examples inside an asynchronous function which you call in the end. Moreover, when sending data from JavaScript to WASM and vise versa, it needs to be serialized to a string. Since the zero knowledge magic happens in the WASM, we rarely deserialize the received data in JavaScript. In case you are curious, you can deeper inspect the data more by calling <data>.parse(). We wrap all data received from WASM into a custom class WasmData that only supports unmarshalling via JSON.parse(<data>) by calling .parse() and displaying the data as string via .toString()

Note: If you run the examples in Typescript and have version 3.8+ installed, you won't be required to do this due to the added top-level await.

async function exec() {
  // Portable gabi example functions...
}
exec();

The creation of attester keys can take 10 to 30 minutes in javascript. Therefore, we recommend using the following example keys which to speed up the process. Please note that you should never use these keys in production.

const portablegabi = require("@kiltprotocol/portablegabi");

const privKey = new portablegabi.AttesterPrivateKey(
  '{"XMLName":{"Space":"","Local":""},"Counter":0,"ExpiryDate":1610554062,"P":"iDYKxuFGt1Xv1aqMLaagjrOPX0hjkOlFrKOp4NPnSBHmQ9SFETUX1M43q3jLsGz+UEWFS3+SS9QpP4CTkl3p/w==","Q":"92MJOhwjESn7QohCCY1oBxsToAfccGoKtE3sBoaNxHWoowSiCy8fMG+B1sO5QU+bV3i1xwvVno9o30RcMoXEaw==","PPrime":"RBsFY3CjW6r36tVGFtNQR1nHr6QxyHSi1lHU8GnzpAjzIepCiJqL6mcb1bxl2DZ/KCLCpb/JJeoUn8BJyS70/w==","QPrime":"e7GEnQ4RiJT9oUQhBMa0A42J0APuODUFWib2A0NG4jrUUYJRBZePmDfA62HcoKfNq7xa44Xqz0e0b6IuGULiNQ==","ECDSA":"MHcCAQEEILO+g4uSDheZ6PSLxR7olFzUhZpeO9tQu84hX6UeIevaoAoGCCqGSM49AwEHoUQDQgAEKvmUz3HIZy890jE78CC9V9BuN8taO+L8GjAeS14v0CL7GCFZ1GMnaSZi4WG3mOjJlJ80CnMowIbUT3Fw1TluFw==","NonrevSk":null}'
);
const pubKey = new portablegabi.AttesterPublicKey(
  '{"XMLName":{"Space":"","Local":""},"Counter":0,"ExpiryDate":1610554062,"N":"g6DWNN/cWep9/lCc6gg0tA8wS1y5LgQx2/fM/wMpYJE8MTZ9SJ3y9kjIBAeSb4aY3vsFhRp8aWsEZzAA0Qu0kW4bzyKN1RU7A0tlmkmDetCxu7Gy2zQMHlTg4YkAVxVYAIIIWhHKHrVLzH7zCsuXos1qm/sthByVdEXv4HPjCZU=","Z":"BiDMFSNGKLIcHJY3tmh2vgiW7D3f5g5b+6Bjf0ns3/rPOg8x0BJ+CzqOLQL+loNIomOzBm/Pk36q3pmPPFMfug80AwUlZOvKTrzj29Agq4DF7p4jruElRyZsdGNjlFkVzILFT/9yrXfjD/9DAHXGm6/4unVnwKP4I0j1r9sLYtg=","S":"Bxm9bNpNLZUM6gy74aR0HW2DadFuy/l+MOdZkG2BiFxbTEP24GXBYA3+d1xajplWEm2iLF4w2OeviIpr8VIzDNy6dXRyGcTnGzj6sVeGlR5u3N+8M2XNH1pNEymLQQbUAt3ogYSWiJW88bxHCf3AZiS91XT1Zh3ENCS9NsyGzt8=","G":"Angd7BuIjTeWGsVLGVCtv+5dx1TMEUr/Z5Fhk7OFUNBexY8fuNfzxfeclgSQpC+nyIAFHc3RB+3Fcs2vOSygopVfLEJo9h7dSjtlcxSZ1wE8YNgouHwfVuq4KWixzIk7Le+IeUzNaQNOL9SI3h5mlxJ5QOO2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Le":597,"LeCommit":456,"LmCommit":592,"LRA":1104,"LsCommit":593,"Lv":1700,"LvCommit":2036,"LvPrime":1104,"LvPrimeCommit":1440},"Issuer":"","ECDSA":"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKvmUz3HIZy890jE78CC9V9BuN8taO+L8GjAeS14v0CL7GCFZ1GMnaSZi4WG3mOjJlJ80CnMowIbUT3Fw1TluFw==","NonrevPk":null}'
);