-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,131 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const Blockchains = { | ||
EOS: 'eos', | ||
ETH: 'eth' | ||
} | ||
|
||
export const BlockchainsArray = Object.keys(Blockchains).map(key => ({ key, value: Blockchains[key] })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as ErrorTypes from './ErrorTypes' | ||
|
||
export const ErrorCodes = { | ||
NO_SIGNATURE: 402, | ||
FORBIDDEN: 403, | ||
TIMED_OUT: 408, | ||
LOCKED: 423, | ||
UPGRADE_REQUIRED: 426, | ||
TOO_MANY_REQUESTS: 429 | ||
} | ||
|
||
export default class Error { | ||
constructor(_type, _message, _code = ErrorCodes.LOCKED){ | ||
this.type = _type | ||
this.message = _message | ||
this.code = _code | ||
this.isError = true | ||
} | ||
|
||
static locked(){ | ||
return new Error(ErrorTypes.LOCKED, "The user's Scatter is locked. They have been notified and should unlock before continuing.") | ||
} | ||
|
||
static promptClosedWithoutAction(){ | ||
return new Error(ErrorTypes.PROMPT_CLOSED, 'The user closed the prompt without any action.', ErrorCodes.TIMED_OUT) | ||
} | ||
|
||
static maliciousEvent(){ | ||
return new Error(ErrorTypes.MALICIOUS, 'Malicious event discarded.', ErrorCodes.FORBIDDEN) | ||
} | ||
|
||
static signatureError(_type, _message){ | ||
return new Error(_type, _message, ErrorCodes.NO_SIGNATURE) | ||
} | ||
|
||
static requiresUpgrade(){ | ||
return new Error(ErrorTypes.UPGRADE_REQUIRED, "The required version is newer than the User's Scatter", ErrorCodes.UPGRADE_REQUIRED) | ||
} | ||
|
||
static identityMissing(){ | ||
return this.signatureError('identity_missing', "Identity no longer exists on the user's keychain") | ||
} | ||
|
||
static signatureAccountMissing(){ | ||
return this.signatureError('account_missing', 'Missing required accounts, repull the identity') | ||
} | ||
|
||
static malformedRequiredFields(){ | ||
return this.signatureError('malformed_requirements', 'The requiredFields you passed in were malformed') | ||
} | ||
|
||
static noNetwork(){ | ||
return this.signatureError('no_network', 'You must bind a network first') | ||
} | ||
|
||
static usedKeyProvider(){ | ||
return new Error( | ||
ErrorTypes.MALICIOUS, | ||
'Do not use a `keyProvider` with a Scatter. Use a `signProvider` and return only signatures to this object. A malicious person could retrieve your keys otherwise.', | ||
ErrorCodes.NO_SIGNATURE | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const MALICIOUS = 'malicious'; | ||
export const LOCKED = 'locked'; | ||
export const PROMPT_CLOSED = 'prompt_closed'; | ||
export const UPGRADE_REQUIRED = 'upgrade_required'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Blockchains } from './Blockchains' | ||
|
||
export default class Network { | ||
constructor(_name = '', _protocol = 'https', _host = '', _port = 0, blockchain = Blockchains.EOS, chainId = ''){ | ||
this.name = _name | ||
this.protocol = _protocol | ||
this.host = _host | ||
this.port = _port | ||
this.blockchain = blockchain | ||
this.chainId = chainId.toString() | ||
} | ||
|
||
static placeholder(){ return new Network() } | ||
|
||
static fromJson(json){ | ||
const p = Object.assign(Network.placeholder(), json) | ||
p.chainId = p.chainId ? p.chainId.toString() : '' | ||
return p | ||
} | ||
|
||
static fromUnique(netString){ | ||
const blockchain = netString.split(':')[0] | ||
if (netString.indexOf(':chain:') > -1) return new Network('', '', '', '', blockchain, netString.replace(`${blockchain}:chain:`, '')) | ||
|
||
const splits = netString.replace(`${blockchain}:`, '').split(':') | ||
return new Network('', '', splits[0], parseInt(splits[1] || 80, 10), blockchain) | ||
} | ||
|
||
unique(){ return (`${this.blockchain}:${this.chainId.length ? `chain:${this.chainId}` : `${this.host}:${this.port}`}`).toLowerCase() } | ||
|
||
hostport(){ return `${this.host}${this.port ? ':' : ''}${this.port}` } | ||
|
||
fullhost(){ return `${this.protocol}://${this.host}${this.port ? ':' : ''}${this.port}` } | ||
|
||
clone(){ return Network.fromJson(JSON.parse(JSON.stringify(this))) } | ||
|
||
isEmpty(){ return !this.host.length } | ||
|
||
isValid(){ return (this.host.length && this.port) || this.chainId.length } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const ERROR = 'error'; | ||
export const PUSH_SCATTER = 'pushScatter'; | ||
export const GET_OR_REQUEST_IDENTITY = 'getOrRequestIdentity'; | ||
export const IDENTITY_FROM_PERMISSIONS = 'identityFromPermissions'; | ||
export const FORGET_IDENTITY = 'forgetIdentity'; | ||
export const REQUEST_SIGNATURE = 'requestSignature'; | ||
export const ABI_CACHE = 'abiCache'; | ||
export const REQUEST_ARBITRARY_SIGNATURE = 'requestArbitrarySignature'; | ||
export const REQUEST_ADD_NETWORK = 'requestAddNetwork'; | ||
export const REQUEST_VERSION_UPDATE = 'requestVersionUpdate'; | ||
export const AUTHENTICATE = 'authenticate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*** | ||
* A set of helpers for Objects/Arrays | ||
*/ | ||
export default class ObjectHelpers { | ||
/*** | ||
* Groups an array by key | ||
* @param array | ||
* @param key | ||
* @returns {*} | ||
*/ | ||
static groupBy(array, key){ | ||
return array.reduce((acc, item) => { | ||
(acc[item[key]] = acc[item[key]] || []).push(item); | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
/*** | ||
* Makes a single level array distinct | ||
* @param array | ||
* @returns {*} | ||
*/ | ||
static distinct(array){ | ||
return array.reduce((a, b) => ((a.includes(b)) ? a : a.concat(b)), []); | ||
} | ||
|
||
/*** | ||
* Makes an object array distinct ( uses deep checking ) | ||
* @param array | ||
* @returns {*} | ||
*/ | ||
static distinctObjectArray(array){ | ||
return array.reduce((a, b) => ((a.find(x => this.deepEqual(x, b))) ? a : a.concat(b)), []); | ||
} | ||
|
||
/*** | ||
* Checks deep equality for objects | ||
* @param objA | ||
* @param objB | ||
* @returns {boolean} | ||
*/ | ||
static deepEqual(objA, objB) { | ||
const keys = Object.keys | ||
const typeA = typeof objA | ||
const typeB = typeof objB | ||
return objA && objB && typeA === 'object' && typeA === typeB ? ( | ||
keys(objA).length === keys(objB).length | ||
&& keys(objA).every(key => this.deepEqual(objA[key], objB[key])) | ||
) : (objA === objB); | ||
} | ||
|
||
/*** | ||
* Flattens an array into a single dimension | ||
* @param array | ||
* @returns {*} | ||
*/ | ||
static flatten(array){ | ||
return array.reduce( | ||
(a, b) => a.concat(Array.isArray(b) ? this.flatten(b) : b), [] | ||
); | ||
} | ||
|
||
/*** | ||
* Flattens an objects keys into a single dimension | ||
* @param object | ||
* @returns {*} | ||
*/ | ||
static objectToFlatKeys(object){ | ||
return this.flatten(Object.keys(object).map((key) => { | ||
if (object[key] !== null && typeof object[key] === 'object') return this.objectToFlatKeys(object[key]) | ||
else return key; | ||
})) | ||
} | ||
|
||
/*** | ||
* Gets a field from an object by string dot notation, such as `location.country.code` | ||
* @param object | ||
* @param dotNotation | ||
* @returns {*} | ||
*/ | ||
static getFieldFromObjectByDotNotation(object, dotNotation){ | ||
const props = dotNotation.split('.'); | ||
return props.reduce((obj, key) => obj[key], object) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default class Plugin { | ||
constructor(_name = '', _type = ''){ | ||
this.name = _name; | ||
this.type = _type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BLOCKCHAIN_SUPPORT = 'blockchain_support'; |
Oops, something went wrong.