The Ownera sdk provides an easy to use set of APIs to work with Ownera FinP2P node for various use cases, the sdk handles most of the heavy lifting for executing operations on the FinP2P network, such as signature templates generation and signing, asset managements, escrow interface and more.
The purpose of this sdk is to provide an interface to the Ownera APIs.
It covers the following:
- Transactional API
- Query API
- Escrow API
- Custody adapter
- Regulation verifiers
It exposes types for Typescript.
To build the lib/
and use the package, just run yarn build
.
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>",
});
Returns Promise with AssetInterface
Usage example:
const { email, name, phoneNumber } = payload.user;
let issuer;
const users = await sdk.owneraAPI.query.getUsers({});
issuer = users.filter((o) => o.email === email)[0];
if (!issuer) {
const { id, publicKey } = await Custody.createAccount({
name,
phoneNumber,
});
const user = await sdk.createUser({
withSignatureProvider: {
publicKey,
signingMethod: signingMethod({ id, custody: sdk.owneraAPI.custodyAdapter! }),
},
});
issuer = await user.getData();
}
// Create Asset
const createdAsset = await sdk.createAsset({
name: "Asset Name",
type: "company",
verifiers: [
{
id: "1",
name: "Accreditation",
provider: "OTHER",
},
],
issuerId: issuer.id,
denomination: {
type: "fiat",
code: "USD"
}});
// get asset data
const createdAssetInfo = await createdAsset.getData();
Returns Promise with UserInterface
Usage example:
// 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),
},
});
Returns AssetInterface
Usage example:
const assetInterface = await getAsset({ assetId });
const asset = await assetInterface.getData();
Returns Promise with UserInterface
Usage example:
const publicKey = "<your-public-key>";
type signingMeth = (r: {custody: CustodyAdapter, id: string}): (hash: string, details?: SignatureDetails) => Promise<string>;
const signingMethod: signingMeth = (r: {custody: CustodyAdapter, id: string}) => {/* Your signingMethod implementation */};
const user = await getSdk().getUser({
userId: r.userId,
withSignatureProvider: {
publicKey: userData.publicKey,
signingMethod: signingMethod({
custody: getSdk().owneraAPI.custodyAdapter!,
id: investorCustodyAccountId,
}),
},
});
user = await sdk.getUser({ userId: profile.id });
#### [Get Organization](./classes/sdk.md#getorganization)
Returns [OrganizationInterface](./interfaces/organizationinterface.md)
Usage example:
```typescript
// get organization API
const org = sdk.getOrganization({ });
More extended recipes you can check here