Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cennznet/crml-attestation

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cennznet/crml-attestation

cennznet's javascript library for supporting identity runtime

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
2
Weekly downloads
 
Created
Source

Cennznet Identity / Attestation

A sdk providing additional features for Cennznet's Identity Service.

Install

$> npm i --save @cennznet/crml-attestation @cennznet/api @cennznet/crml-generic-asset @cennznet/crml-cennzx-spot 

Basic Setup

Alright, let's get started with the code. If you want the full demo code without the explanations, see the examples/folder

First create a file and name it index.js and write the following two lines in:

const {Api} = require('@cennznet/api')
const {Attestation} = require('@cennznet/crml-attestation')

This loads up a version of the Attestation SDK that we will be using to call the code. This will be the foundation of your attestation requests.

Creating your wallet and issuer account

In order to send claims, we have to create a wallet, to do so we need to import @cennznet/wallet so go ahead and add these lines to your file under the attestation imports

const {SimpleKeyring, Wallet} = require('@cennznet/wallet')
const { stringToU8a } = require('@cennznet/util')
const simpleKeyring = new SimpleKeyring();
const wallet = new Wallet();

Alright, now we will need an account from which to issue a claim from. Navigate to CENNZnet UI and create an account by navigating to Accounts -> Create Account and selecting "Raw Seed" on the dropdown. Cennznet UI Create Account

Now that you've created that, let's create an object called "issuer" in your code under the wallet instantiation

const issuer = {
  address: '<your address here>',
  seed: stringToU8a(('<your seed here>' as any).padEnd(32, ' ')),
};

Substrate accepts a Uint-8 Array as the signing mechanism, and we have a string so we must convert it to a Uint-8 Array. If your seed is less than 32 characters long, use String.prototype.padEnd to pad it with blank lines so that it can become 32 characters long and is consistent with the seed.

Funding the issuer account

In order to issue a claim to someone, we need to have some money, so navigate to the CENNZnet Faucet and transfer some money to your public address.

Cennznet Faucet

Setting up the holder account

Alright, now that we've got our issuer account set up, we need to set up our holder account. Please follow the instructions on setting up an issuer account again, but do not fund it.

You should now create an object similar to this:

const holder = {
  address: '<your new holder address here>',
  seed: stringToU8a(('<your new holder seed here>' as any).padEnd(32, ' ')),
};

Sending a claim with one issuer

Add the following lines to your file:

async function main () {
    simpleKeyring.addFromSeed(issuer.seed);
    const api = await Api.create({provider: 'wss://rimu.unfrastructure.io/ws?apikey=***'});
    const passphrase = '<insert issuer passphrase here>';
    await wallet.createNewVault(passphrase);
    await wallet.addKeyring(simpleKeyring);
    api.setSigner(wallet);
    const attestation = new Attestation(api);
}
main()

This spins up a version of our attestation api inside the main function, we will now be writing all of our code inside the main function

To create a claim add the following lines inside the main function

const topic = 'test'
const value = '1234'
const claim = await attestation.setClaim(
    holder.address,
    topic,
    value,
);

await claim.signAndSend(issuer.address, async ({result, event}) => {
    if (result.isFinalized && events !== undefined) {
      const { data } = events[0].event.toJSON();
      console.log(data)
    }
});

Topics should be ASCII strings that don't have any non typeable characters and be at most 32 characters and Values should be strings of a max of 64 character length.

If you've done everything properly, then you should get a response object of something similar to this:

[ '5EfqejHV2xUUTdmUVBH7PrQL3edtMm1NQVtvCgoYd8RumaP3',
  '5FPCjwLUkeg48EDYcW5i4b45HLzmCn4aUbx5rsCsdtPbTsKT',
  1952805748,
  825373492 ]

FAQs

Package last updated on 27 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc