1.6.4 • Published 4 months ago

@ultraos/ultra-signer-lib v1.6.4

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

ultra-signer-lib

Wharfkit provides a lot of the functionality that Ultra needs but we want to simplify our transactions where possible.

This library aims to provide similar functionality to eosjs without the added complexity of using @wharfkit/antelope directly.

Features

  • Sign Messages
  • Sign Transactions with Multiple Private Keys
  • Use Google KMS Signing
  • Sign Messages with KMS
  • Sign Transactions with KMS
  • Sign Transactions with Keosd

Contents

Installation

npm i @ultraos/ultra-signer-lib

Usage

Transact

import { API } from '@ultraos/ultra-signer-lib';

// Compromised key, do not use for production.
const publicKey = 'EOS8NcQNcaR1eRyLPnCBoq6KRUGYHW5CDBVTWgLBii3Vas4dXTgMf';
const privateKey = '5JNcnnozrvvgmqP7oigzD9UuNn9JLCtmL69qPTmvz7cMAtBTRZZ';

const api = new API(TEST_ENDPOINT, { signingMode: 'PRIVATE_KEY', privateKeys: [privateKey] });

// This is asynchronous, wrap it in an async function, or use then
const result = await api.transact([
    {
        account: 'eosio.token',
        name: 'transfer',
        authorization: [{ actor: from, permission: 'active' }],
        data: {
            from: 'alice',
            to: 'bob',
            quantity: '0.00000000 UOS',
            memo: 'hi',
        },
    },
]);

if (result.status) {
    console.log(`Transaction Successful!`);
    console.log(result.data);
} else {
    console.log(`Transaction Failed!`);
    console.log(result.data);
}

Sign & Verify Message

import { Signer } from '@ultraos/ultra-signer-lib';

// Note that these keys are exposed and should not be used at all or in production
const publicKey = 'EOS8NcQNcaR1eRyLPnCBoq6KRUGYHW5CDBVTWgLBii3Vas4dXTgMf';
const privateKey = '5JNcnnozrvvgmqP7oigzD9UuNn9JLCtmL69qPTmvz7cMAtBTRZZ';

const originalMessage = 'hello world!';
const signature = Signer.sign(originalMessage, privateKey);

console.log(Signer.verify(signature, originalMessage, publicKey));

Keosd - Sign Transaction

import { API } from '@ultraos/ultra-signer-lib';

const api = new API(TEST_ENDPOINT, { signingMode: 'KEOSD', keosdEndpoint: KEOSD_ENDPOINT });
const result = await api.transact([
    {
        account: 'eosio.token',
        name: 'transfer',
        authorization: [{ actor: from, permission: 'active' }],
        data: { from, to, quantity, memo },
    },
]);

KMS Setup

KMS can be used to create a shared private key that signs transactions through Google APIs.

Creating a key should be -> HSM, Asymmetric Sign, Elliptic Curve secp256k1 with SHA256 Digest

import { API, SignerKMS } from '@ultraos/ultra-signer-lib';

const credentials = {
    project_id: 'some google project identifier',
    private_key: 'the private key you get from the .json file when you create a kms key',
    client_email: 'service account email',
    client_id: 'service account client id',
};

const keypath = {
    project: 'some google project identifier',
    location: 'global',
    keyRing: 'key ring name',
    cryptoKey: 'key name',
    cryptoKeyVersion: '1',
};

const kmsService = new SignerKMS(credentials, keypath);
const api = new API(TEST_ENDPOINT, { signingMode: 'KMS', KMS: kmsService });

KMS - Transact

import { API, SignerKMS } from '@ultraos/ultra-signer-lib';

const api = new API(TEST_ENDPOINT, { signingMode: 'KMS', KMS: kmsService });
const result = await api.transact([
    {
        account: 'eosio.token',
        name: 'transfer',
        authorization: [{ actor: from, permission: 'active' }],
        data: { from, to, quantity, memo },
    },
]);

KMS - Sign & Verify Message

import { Signer, SignerKMS } from '@ultraos/ultra-signer-lib';

const originalMessage = 'hello world!';
const signature = Signer.sign(originalMessage, kmsService);
console.log(Signer.verify(signature, originalMessage, kmsService));

Additional Documentation

Any additional documentation for individual functions and utilities can be found here:

Development

  • Install Node 18+

Install Library

To install dependencies:

npm i

Test

npm run test

Build Library

npm run build
1.6.4

4 months ago

1.6.3

4 months ago

1.6.2

5 months ago

1.6.1

5 months ago

1.6.0

6 months ago

1.5.1

7 months ago

1.5.0

7 months ago

1.4.0

7 months ago

1.2.0

7 months ago

1.1.0

7 months ago