@owneraio/finp2p-sdk-js
TypeScript icon, indicating that this package has built-in type declarations

0.14.10 • Public • Published

Ownera API service

The purpose of this sdk is to provide an interface to the Ownera APIs.
It covers the following:

It exposes types for Typescript.

To build the lib/ and use the package, just run yarn build.

Detailed documentation available here

Setup

You need to create a .env file in your project with the following keys

NODE_MSPID=<organization_id, e.g: bank-us>
OWNERA_API_ADDRESS=<API url, e.g: network-bank-us.api.local.ownera.io>

Usage

Core

import { Sdk } from '@owneraio/finp2p-sdk-js';

const sdk = new Sdk({
  orgId: 'myOrdId',
  owneraAPIAddress: 'https://my-ownera-node.io',
  owneraRASAddress: 'https://my-ownera-reg-app-store.io',
  authConfig: { 
    apiKey: '<my-api-key>',
    secret: { 
      type: 1|2, 
      raw: '<my-stringified-private-key>',
    },
  },
  custodyAdapterBaseURL: '<optional-custody-url>',
});

const asset = await sdk.createAsset({
  name: `my-asset-name`,
  type: 'Company',
  issuerId: 'asset-issuer-finp2p-id',
  verifiers: [],
  denomination: { type: 'fiat', code: 'USD' },
});

Inner functions

import { Asset, AssetConfig, OwneraAPI } from '@owneraio/finp2p-sdk-js';

export default async () => {
  const config: AssetConfig = {
    recipientRules: [],
    recipientClaimProviders: [],
  };

  // Create Asset
  const result = await OwneraAPI.profiles.createAsset({ config });
  // Get Assets
  const assets: Asset[] = await OwneraAPI.oss.getAssets({});
  console.info(assets);
};

Create user

// Create signing method using custody adapter
const signingMethod = (custody: CustodyAdapter, id: string) => async (hash: string) => {
  let attempt = 0;
  let signatureResponse = await custody.createSignature({ id, hash });
  const signatureId = signatureResponse.id;
  const doRetry = !['FAILED', 'COMPLETED'].includes(signatureResponse.status);
  while (doRetry && attempt < 10) {
    signatureResponse = await custody.getSignature({ signatureId });
    attempt = attempt + 1;
  }

  if (doRetry && attempt === 10) {
    throw {
      code: 408,
      name: 'SignatureError',
      message: 'Timeout - unable to get signature',
      data: signatureResponse,
    };
  }

  if (signatureResponse.status === 'FAILED') {
    throw {
      code: 500,
      name: 'SignatureError',
      message: 'Failure - unable to get signature',
      data: signatureResponse,
    };
  }

  return Promise.resolve(signatureResponse.signature);
};

// Create user 
const uniqueIdentifier = Date.now();
const account = await sdk.owneraAPI.custodyAdapter!.createAccount({
  uniqueIdentifier,
  name: `${uniqueIdentifier} custody account`,
});
const user = await sdk.createUser({
  withSignatureProvider: {
    publicKey: account.publicKey,
    signingMethod: signingMethod(sdk.owneraAPI.custodyAdapter!, account.id),
  },
});

Keywords

none

Install

npm i @owneraio/finp2p-sdk-js

Homepage

ownera.io/

DownloadsWeekly Downloads

261

Version

0.14.10

License

SEE LICENSE IN LICENSE.md

Unpacked Size

309 kB

Total Files

269

Last publish

Collaborators

  • owneraadmin