v.8 by Sergey Chernov
2018-11-01 23:11

UMI usage examples


We recommend to use Universa ruby gem.

If you still want to play with UMI gits, you will need to install farcall gem first. The sample assumes UMI archive is unpacked into ./uniUMI directory. Now you can make UMI connection manually:

Simple UMI connection

This sample generates new private key and saves it to a file:

require 'farcall'
require 'open3'
require 'base64'

 # Start UMI in default mode. We need only stdin/out
UMI_in,UMI_out = Open3.popen3('./uniUMI/bin/uniUMI')

 # Now create endpoint with it. Our UMI uses \n as delimiter, so we should specify it:
UMI = Farcall::Endpoint.new(
    Farcall::JsonTransport.create(delimiter: "\n", input: UMI_out,output: UMI_in)

 # call key creation
private_key_ref = UMI.sync_call("instantiate", "PrivateKey", 2048)
 # call pack for created key object
packed_key_64 = UMI.sync_call("invoke", private_key_ref.id, "pack")[:base64]
 # And save in universa binary format
open('new_key.private.unikey', 'wb') { |f| f << Base64.decode64(packed_key_64) }

Very simple, but it could be ever simpler if we create some class to incapsulate UMI boilerplate and reference lifetime tracking. All this and much more is done with our universa ruby gem