swarm-io-governance
v0.2.5
Published
`npm install swarm-io-governance`
Downloads
31
Readme
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
- [x] Styling updates
- [x] New functionality: Transactions section, with transactions stored in local storage
- [x] New functionality: notifications are now displayed giving the status of transactions
- [x] Updated requests to work with API changes
- [x] Bug fix to catch duplicated requests
0.2.0 -> 0.2.1
- [x] Updates to docs
0.1.7 -> 0.2.0
- [x] Removed
democHash
from thedemocracyDetails
prop - [x]
src20Address
withindemocracyDetails
is nowtokenId
- [x] Added a
debugMode
prop, which can be enabled during testing to log data to the console - [x] 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
- [x] 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 intrue
if the user is an admin of an IO, they will have the ability to create proposalsdebugMode
Boolean not required - pass intrue
which will log additional information to the console for testingstellarPk
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 parametersname
String - The name of the IO, this is only used to render the name within the componenttokenId
String - the stellar reference to the tokenvotingNet
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 thesignRequestEvent
section)pubkey
String - The stellar public key of the usersignature
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 asignRequestObject
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;
}
}