0.2.5 • Published 6 years ago

swarm-io-governance v0.2.5

Weekly downloads
58
License
-
Repository
-
Last release
6 years ago

Swarm Governance Component

npm install swarm-io-governance

Changelog

0.2.1 -> ... -> 0.2.5

NOTE - No changes to props or events in this version

  • Styling updates
  • New functionality: Transactions section, with transactions stored in local storage
  • New functionality: notifications are now displayed giving the status of transactions
  • Updated requests to work with API changes
  • Bug fix to catch duplicated requests

0.2.0 -> 0.2.1

  • [x] Updates to docs

0.1.7 -> 0.2.0

  • Removed democHash from the democracyDetails prop
  • src20Address within democracyDetails is now tokenId
  • Added a debugMode prop, which can be enabled during testing to log data to the console
  • Event type signRequestEvent now passes an object instead of just the data to sign. This object contains a request type, type and data to sign, toSign
  • Added new detailed example of how to handle the signRequestEvent

How to use

Install and register the component as per usual

<SwmGovernance
	:ioAdmin="<boolean: is the voter an admin of this democracy>"
    :debugMode="<boolean: debug mode>"
    :stellarPk="<stellar PK of voter>"
    :votingSk="<securely generated ethereum privkey for voting>"
    :democracyDetails="<object with details about the democracy>"
    :signResponse="<object that is updated following signature requests>"
    @signRequestEvent="<function responding to signature requests>"
/>

Props

  • ioAdmin Boolean not required - pass in true if the user is an admin of an IO, they will have the ability to create proposals
  • `debugMode` **Boolean** _not required_ - pass in `true` which will log additional information to the console for testing
  • stellarPk String required - The public key corresponding to the users stellar address
	stellarPk: "GCFEX6MYIIHNY26CHTUVOTQWNUAQ3RWOKC2DBYW2MHLYYWAUR2HGWQLX",
  • votingSk String required - The HMAC deterministically generated voting secret key - this should be 32bytes as eth hex (0xa34b...)
	votingSk: "0x7d2479e16009181d2ed96b88352dad11cb321404f5f879b7d0e1c4c33b0a0aa3",
  • democracyDetails Object required - (in progress) object with the following parameters
    • name String - The name of the IO, this is only used to render the name within the component
    • tokenId String - the stellar reference to the token
    • votingNet String - either "mainnet" or "testnet" depending on whether the component is on staging production
democracyDetails: {
	name: "NIAH Fund",
	tokenId: "TBC",
	votingNet: "testnet" // should be either "mainnet" or "testnet"
},
  • signResponse Object - This object should be empty until a @signRequestEvent occurs, when the signature response object should be passed in after being signed. This object needs to contain:
    • request String - The delegation request that has been signed (see more below in the signRequestEvent section)
    • pubkey String - The stellar public key of the user
    • signature String - Signed request, 64 bytes in hex
const signResponse = {
    request,
    pubKey: kp.publicKey(),
    signature: sig.toString('hex')  // if it's a buffer
};

Events

  • signRequestEvent - The only event in the component so far. This event passes a signRequestObject which contains the request type and data requested to be signed. Full example of this signing below.
{
    type: String, // Will be either "proposal" or "delegation"
    toSign: String
};

Example signRequestEvent

The signRequestEvent example below has been created using the stellar-base library

methods: {
		onSignRequest(request) {
			// Check to see if the request type is a delegation or proposal
            switch (request.type) {
                case 'delegation':
                    return this.handleDelegationSign(request);
                case 'proposal':
                    return this.handleProposalSign(request);
                default:
                    throw new Error('Invalid request type')
            }
        },

        handleDelegationSign (request) {
            const { toSign, type } = request
            // Request should be 32 bytes + 0x prefix = 66 character
            if (toSign.length !== 66) {
                throw new Error('Request is not the correct length');
            }
            // Grab first 9 bytes + 0x which makes up the first part of the prefix (next 3 bytes are the nonce)
            const prefix = toSign.substring(0, 20);
            const knownPrefix = 'SV-ED-ETH';
            const knownPrefixHex = web3.utils.toHex(knownPrefix);
            if (prefix !== knownPrefixHex) {
                throw new Error('Prefix is not correct');
            }
            // Sign the data to sign
            const kp = StellarBase.Keypair.fromSecret(this.stellarSk);
            const sig = kp.sign(toSign);
            // Create a sign response object with the request, type, public key and signature in hex format
            const signResponse = {
                toSign,
                type,
                pubKey: kp.publicKey(),
                signature: sig.toString('hex'),
            };
            // Pass the signed object back to the swarm governance component
            this.signResponse = signResponse;
        },

        handleProposalSign (request) {
            const { toSign, type } = request
            // toSign will be a stringified JSON ballotSpec object - parse it to check the contents
            const parsed = JSON.parse(toSign)
            // Check to make sure it has the required properties
            if (!parsed.hasOwnProperty('ballotInner') || !parsed.hasOwnProperty('optionsInner') || !parsed.hasOwnProperty('subgroupInner')) {
                throw new Error('Ballot requested for signing does not contain the required properties')
            }

            // Sign the 'toSign' string
            const kp = StellarBase.Keypair.fromSecret(this.stellarSk);
            const sig = kp.sign(toSign);

            // Create a sign response object with the request, type, public key and signature in hex format
            const signResponse = {
                toSign,
                type,
                pubKey: kp.publicKey(),
                signature: sig.toString('hex'),
            };
            // Pass the signed object back to the swarm governance component
            this.signResponse = signResponse;
        }

}
0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago