@dorgtech/id-dao-client
## Identity Definition Form An Identity is defined by a metadata JSON object that's stored in IPFS. The IdentityDefinition & IdentityDefinitionForm classes aim to make it easier to create and validate this metadata JSON object. Below is an example of (1)
Last updated 6 months ago by dorgjelli .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @dorgtech/id-dao-client 
SYNC missed versions from official npm registry.

ID-DAO Client Library

Identity Definition Form

An Identity is defined by a metadata JSON object that's stored in IPFS. The IdentityDefinition & IdentityDefinitionForm classes aim to make it easier to create and validate this metadata JSON object. Below is an example of (1) deserializing an existing JSON definition (2) validating it and resolving any errors (3) serializing it back to JSON.

Note: IdentityDefinitionForm is a "formstate" form. The below example should suffice, but for more information about using the formstate library, see: https://formstate.github.io/#/?id=quick-example

import {
  IdentityDefinition,
  IdentityDefinitionForm,
  serialize,
  deserialize
} from "@dorgtech/id-dao-client";

// Eead some JSON from a file or a request body
let json =
`{
  "name": "Bob Hutchings",
  "address": "bad address",
  "uploads": {
    "selfie": {
      "host": "bad host type",
      "hash": "QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o"
    },
    "video": {
      "host": "gun",
      "hash": "QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o"
    }
  },
  "socialPosts": {
    "twitter": "https://twitter.com/dOrgJelli/status/1172340539376599046",
    "github": "https://gist.github.com/dOrgJelli/5088cddf1c58d417b9654500b49d4aa2"
  },
  "version": "1"
}`;

// Convert to IdentityDefinition
let data: IdentityDefinition = deserialize(json);

// Create an IdentityDefinitionForm
const form = new IdentityDefinitionForm();

// Initialize it with our data
form.data = data;

// Run the form's validation over our IdentityDefinition data
const res = await form.validate();

if (res.hasError) {
  // bad address
  console.log(form.error);
}

// Make an edit to a field of the form
form.$.address.value = "0xfD0174784EbCe943bdb8832Ecdea9Fea30e7C7A9";

// Validate our form again
...
// uploads.selfie.host contains a bad value

// Make an edit
form.$.uploads.$.selfie.$.host.value = "ipfs";

// Validate our form again
...

// All checks pass, let's turn it back into JSON
data = form.data;
json = serialize(data);

Current Tags

  • 1.1.0-rc.4-v3                                ...           latest (6 months ago)

22 Versions

  • 1.1.0-rc.4-v3                                ...           6 months ago
  • 1.1.0-rc.4-v2                                ...           6 months ago
  • 1.1.0-rc.4-v1                                ...           6 months ago
  • 1.1.0-rc.4                                ...           6 months ago
  • 1.1.0-rc.3                                ...           6 months ago
  • 1.1.0-rc.2                                ...           6 months ago
  • 1.1.0-rc.1-v4                                ...           6 months ago
  • 1.1.0-rc.1-v3                                ...           6 months ago
  • 1.1.0-rc.1-v2                                ...           8 months ago
  • 1.0.10-rc.1                                ...           8 months ago
  • 1.0.10                                ...           8 months ago
  • 1.0.9                                ...           8 months ago
  • 1.0.8                                ...           8 months ago
  • 1.0.7                                ...           8 months ago
  • 1.0.5                                ...           8 months ago
  • 1.0.4                                ...           8 months ago
  • 1.0.3                                ...           8 months ago
  • 0.0.5                                ...           8 months ago
  • 0.0.4                                ...           8 months ago
  • 0.0.3                                ...           8 months ago
  • 0.0.2                                ...           8 months ago
  • 0.0.1                                ...           8 months ago
Downloads
Today 0
This Week 0
This Month 22
Last Day 0
Last Week 22
Last Month 0
Dependencies (9)
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |