GithubHelp home page GithubHelp logo

kord.js's People

Contributors

lmars avatar lukehedger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kord.js's Issues

Add getProfileClaimSubPropertyFromProperty

/**
 * Get the sub-property of a META Identity Profile Claim from the claim's property
 *
 * @example getProfileClaimSubPropertyFromProperty('profile.name') // => 'name'
 *
 * @param  {String} property Profile claim property
 * @return {String}          Profile claim sub-property
 */
export const getProfileClaimSubPropertyFromProperty = property => {
  return property.replace(new RegExp(`${PROFILE_CLAIM_PREFIX}.`, 'i'), '')
}

Update `createIdentityClaimObject` method

  • Rename createIdentityClaimObject to createVerifiableIdentityClaimObject.
  • Add new API requirements:
/**
 * Utility function to create a valid META Claim object to verify a new claim
 *
 * @param  {Object} account            Ethereum account object
 * @param  {String} account.address    Account Ethereum address
 * @param  {String} account.privateKey Account private key
 * @param  {Object} claimMessage       Raw claim message
 * @param  {String} subject            META-ID `id` of subject (hash of `username`)
 * @param  {Object} extraData          Any extra properties to add to claim object
 * @return {Object}                    META Claim object
 */
export const createVerifiableIdentityClaimObject = (
  account,
  claimMessage,
  subject,
  extraData = {}
) => {
  return {
    address: account.address,
    claimHash: bufferToHex(sha3(claimMessage)),
    claimMessage: claimMessage,
    subject: subject,
    signature: accounts.signMessage(claimMessage, account.privateKey),
    ...extraData,
  }
}

This is used by dapps to send claim verification requests to META Identity Claims Services

Add validation for method parameters across all packages

  • Validate method arguments
  • Provide informative error messages

UPDATE: After a brief look into the options available, this is not feasible for now.

A thin utility that can wrap all library methods would be ideal. prop-types looks like it could do the job and can be extended with customProps for non-standard props (like the Ethereum-specific props).

Some props/checks we'd need for now:

Add method to create verified `ClaimInput` object

  • createVerifiedIdentityClaimObject => valid ClaimInput props
ClaimInput: {
  claim, // raw claim value
  issuer, // META-ID `id` of issuer
  property, // claim key
  signature, // claim signed by issuer
  subject, // META-ID `id` of subject
}

This is used by META Identity Claims Services when returning verified claims data.

export const createVerifiedIdentityClaimObject = (claimMessage, subject) => {
  // META Claims Service config
  const metaClaimsService = {
    ... // from somewhere
  }

  // set the claim value being verified
  const verifiedClaimValue = claimMessage // raw claim value

  // generate verified claim buffer
  const verifiedClaimBuffer = sha3(Buffer.concat([
    toBuffer(metaClaimsService.id), // issuer ID
    toBuffer(subject), // subject ID
    toBuffer(metaClaimsService.property), // claim key
    toBuffer(verifiedClaimValue), // claim value
  ]))

  // generate ECDSA signature of verified claim buffer using the MCS private key
  const verifiedClaimSignatureObject = ecsign(
    verifiedClaimBuffer,
    Buffer.from(metaClaimsService.privateKey, 'hex')
  )

  // convert ECDSA signature buffer to hex value
  const verifiedClaimSignature = toRpcSig(
    verifiedClaimSignatureObject.v,
    verifiedClaimSignatureObject.r,
    verifiedClaimSignatureObject.s
  )

  // return response body
  return {
    claim: verifiedClaimValue,
    issuer: metaClaimsService.id,
    property: metaClaimsService.property,
    signature: verifiedClaimSignature,
    subject: subject,
  }
}

Add version to core export

  • Add generated VERSION global to core rollup.config.js:
import replace from 'rollup-plugin-replace'

const pkg = require('./package.json')

plugins: [
  replace({
    values: {
      RPC: JSON.stringify(process.env.RPC),
      VERSION: JSON.stringify(pkg.version),
    },
  }),
  ...
]
  • Then export:
export {
  ...,
  version: VERSION,
}
  • Add a test to check version is defined and equal to latest version

IdentityClaims: createProfileMetaIdentityClaim method should return a valid verified identity claim object

The createProfileMetaIdentityClaim method returns an invalid identity claim object - specifically, the returned signature value is incorrect.

The method should actually use the createVerifiedIdentityClaimObject to generate a valid identity claim object like so:

/**
 * Create a valid META Identity Claim object for a profile claim
 * This is a self-issued claim, usually referencing a Swarm hash of profile data
 *
 * @param  {String} claimMessage      Raw identity claim message
 * @param  {Object} issuer            Claim issuer data object
 * @param  {String} issuer.id         META Identity `id` of claim issuer
 * @param  {String} issuer.privateKey Private key of claim issuer
 * @param  {String} subProperty       Type of profile claim contained in `claimMessage`
 * @return {Object}                   Verified META Identity Claim object
 */
export const createProfileMetaIdentityClaim = (
  claimMessage,
  issuer,
  subProperty
) => {
  return createVerifiedIdentityClaimObject(
    claimMessage,
    {
      id: issuer.id,
      privateKey: issuer.privateKey,
      property: `profile.${subProperty}`,
    },
    issuer.id
  )
}

Documentation

  • Installation
  • meta.js core API
  • identity API
  • identity-claims API

Add isProfileClaim

/**
 * Check if a META Identity claim is a profile claim
 *
 * @param  {Object}  claim META Identity Claim object
 * @return {Boolean}       Profile claim boolean
 */
export const isProfileClaim = claim => {
  return claim.property.startsWith(`${PROFILE_CLAIM_PREFIX}.`)
}

Fix package dependencies

  • Specify all meta.js inter-package dependencies
  • Move config object from core to @meta.js/shared to avoid unnecessary inclusion of all modules for packages that depend on config values.

Add method for generating profile claims

As per discussion in kord-network/go-kord#57 - add a method to create META Identity Claim objects for profile attributes such as images, common names and web addresses.

export const createProfileMetaIdentityClaim = (account, claim, subProperty) => {
  return {
    claim: claim, // Swarm hash
    issuer: account.address, // self-issued claim
    property: `profile.${subProperty}`, // eg. `profile.image`
    signature: signMessage(claim, account.privateKey),
    subject: account.address,
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.