Skip to content

Commit

Permalink
Merge pull request #29 from echoprotocol/develop
Browse files Browse the repository at this point in the history
v1.10.2
  • Loading branch information
vital-33 authored Aug 29, 2019
2 parents 3ba310c + 228535e commit dfaf675
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 292 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ build.publish:
- 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "https://www.googleapis.com/chromewebstore/v1.1/items/${CHROME_APP_ID}/publish?publishTarget=default"'
only:
- tags
except:
- /^.*rc.*$/
tags:
- docker
29 changes: 21 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@ jobs:
if: branch IN (develop, master) AND type = pull_request
script: npm run test

# - stage: build
# name: "Build Artifacts"
# if: (branch = master OR branch = develop) AND type = push
# addons:
# artifacts:
# working_dir: build/zip/
# paths:
# - echo_bridge.zip
# script:
# - npm run build-ext
# - "echo \"Download URL: https://${ARTIFACTS_BUCKET}.s3.amazonaws.com/echoprotocol/bridge-extension/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/echo_bridge.zip\""

- stage: build
name: "Build Artifacts"
if: (branch = master OR tag IS present) AND type = push
addons:
artifacts:
working_dir: build/zip/
paths:
- echo_bridge.zip
name: "Build Tag Artifacts"
if: tag IS present
script:
- npm run build-ext
- "echo \"Download URL: https://${ARTIFACTS_BUCKET}.s3.amazonaws.com/echoprotocol/bridge-extension/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/echo_bridge.zip\""
deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file: build/zip/echo_bridge.zip
skip_cleanup: true
on:
tags: true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) ECHO DEVELOPMENT LTD
Copyright (c) Echo Technological Solutions LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ED25519.verifyMessage(signature, message, publicKey);

The MIT License (MIT)

Copyright (c) ECHO DEVELOPMENT LTD
Copyright (c) Echo Technological Solutions LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion config/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"96": "images/96.png",
"128": "images/128.png"
},
"version": "1.10.0",
"version": "1.10.2",
"background": {
"scripts": [
"background.js"
Expand Down
6 changes: 3 additions & 3 deletions examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const tr = window.echojslib.echo.createTransaction();

const bytecode = '606060405260126006556000600755341561001957600080fd5b604051602080610dd283398101604052808051600160a060020a03331660008181526001602052604080822082905590805560048054600160a060020a0319168317905591935091507fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed94905160405180910390a2600555610d338061009f6000396000f3006060604052600436106101485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461014d57806307da68f514610172578063095ea7b31461018757806313af4035146101bd57806318160ddd146101dc57806323b872dd146101ef578063313ce5671461021757806340c10f191461022a57806342966c681461024c5780635ac801fe1461026257806370a082311461027857806375f12b21146102975780637a9e5e4b146102aa5780638da5cb5b146102c957806395d89b41146102f85780639dc29fac1461030b578063a0712d681461032d578063a9059cbb14610343578063b753a98c14610365578063bb35783b14610387578063be9a6555146103af578063bf7e214f146103c2578063daea85c5146103d5578063dd62ed3e146103f4578063f2d5d56b14610419575b600080fd5b341561015857600080fd5b61016061043b565b60405190815260200160405180910390f35b341561017d57600080fd5b610185610441565b005b341561019257600080fd5b6101a9600160a060020a03600435166024356104e0565b604051901515815260200160405180910390f35b34156101c857600080fd5b610185600160a060020a036004351661050d565b34156101e757600080fd5b61016061058c565b34156101fa57600080fd5b6101a9600160a060020a0360043581169060243516604435610592565b341561022257600080fd5b610160610707565b341561023557600080fd5b610185600160a060020a036004351660243561070d565b341561025757600080fd5b6101856004356107d3565b341561026d57600080fd5b6101856004356107e0565b341561028357600080fd5b610160600160a060020a0360043516610806565b34156102a257600080fd5b6101a9610821565b34156102b557600080fd5b610185600160a060020a0360043516610831565b34156102d457600080fd5b6102dc6108b0565b604051600160a060020a03909116815260200160405180910390f35b341561030357600080fd5b6101606108bf565b341561031657600080fd5b610185600160a060020a03600435166024356108c5565b341561033857600080fd5b610185600435610a33565b341561034e57600080fd5b6101a9600160a060020a0360043516602435610a3d565b341561037057600080fd5b610185600160a060020a0360043516602435610a4a565b341561039257600080fd5b610185600160a060020a0360043581169060243516604435610a5a565b34156103ba57600080fd5b610185610a6b565b34156103cd57600080fd5b6102dc610b04565b34156103e057600080fd5b6101a9600160a060020a0360043516610b13565b34156103ff57600080fd5b610160600160a060020a0360043581169060243516610b39565b341561042457600080fd5b610185600160a060020a0360043516602435610b64565b60075481565b61045733600035600160e060020a031916610b6f565b151561046257600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff0000000000000000000000000000000000000000191660a060020a179055565b60045460009060a060020a900460ff16156104fa57600080fd5b6105048383610c7b565b90505b92915050565b61052333600035600160e060020a031916610b6f565b151561052e57600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9460405160405180910390a250565b60005490565b60045460009060a060020a900460ff16156105ac57600080fd5b33600160a060020a031684600160a060020a0316141580156105f65750600160a060020a038085166000908152600260209081526040808320339094168352929052205460001914155b1561065457600160a060020a038085166000908152600260209081526040808320339094168352929052205461062c9083610ce7565b600160a060020a03808616600090815260026020908152604080832033909416835292905220555b600160a060020a0384166000908152600160205260409020546106779083610ce7565b600160a060020a0380861660009081526001602052604080822093909355908516815220546106a69083610cf7565b600160a060020a03808516600081815260016020526040908190209390935591908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b60065481565b61072333600035600160e060020a031916610b6f565b151561072e57600080fd5b60045460a060020a900460ff161561074557600080fd5b600160a060020a0382166000908152600160205260409020546107689082610cf7565b600160a060020a0383166000908152600160205260408120919091555461078f9082610cf7565b600055600160a060020a0382167f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968858260405190815260200160405180910390a25050565b6107dd33826108c5565b50565b6107f633600035600160e060020a031916610b6f565b151561080157600080fd5b600755565b600160a060020a031660009081526001602052604090205490565b60045460a060020a900460ff1681565b61084733600035600160e060020a031916610b6f565b151561085257600080fd5b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167f1abebea81bfa2637f28358c371278fb15ede7ea8dd28d2e03b112ff6d936ada460405160405180910390a250565b600454600160a060020a031681565b60055481565b6108db33600035600160e060020a031916610b6f565b15156108e657600080fd5b60045460a060020a900460ff16156108fd57600080fd5b33600160a060020a031682600160a060020a0316141580156109475750600160a060020a038083166000908152600260209081526040808320339094168352929052205460001914155b156109a557600160a060020a038083166000908152600260209081526040808320339094168352929052205461097d9082610ce7565b600160a060020a03808416600090815260026020908152604080832033909416835292905220555b600160a060020a0382166000908152600160205260409020546109c89082610ce7565b600160a060020a038316600090815260016020526040812091909155546109ef9082610ce7565b600055600160a060020a0382167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca58260405190815260200160405180910390a25050565b6107dd338261070d565b6000610504338484610592565b610a55338383610592565b505050565b610a65838383610592565b50505050565b610a8133600035600160e060020a031916610b6f565b1515610a8c57600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff000000000000000000000000000000000000000019169055565b600354600160a060020a031681565b60045460009060a060020a900460ff1615610b2d57600080fd5b61050782600019610c7b565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b610a55823383610592565b600030600160a060020a031683600160a060020a03161415610b9357506001610507565b600454600160a060020a0384811691161415610bb157506001610507565b600354600160a060020a03161515610bcb57506000610507565b600354600160a060020a031663b70096138430856000604051602001526040517c010000000000000000000000000000000000000000000000000000000063ffffffff8616028152600160a060020a039384166004820152919092166024820152600160e060020a03199091166044820152606401602060405180830381600087803b1515610c5957600080fd5b6102c65a03f11515610c6a57600080fd5b505050604051805190509050610507565b600160a060020a03338116600081815260026020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b8082038281111561050757600080fd5b8082018281101561050757600080fd00a165627a7a72305820c3b70a68c1ccfc4b88f478523cfc01b3108a40e2c6d0132d5b736b0c3034972800294d4b520000000000000000000000000000000000000000000000000000000000';

tr.addOperation(echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT, {
tr.addOperation(echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE, {
code: bytecode,
eth_accuracy: false,
registrar: '1.2.1',
Expand All @@ -24,10 +24,10 @@ await tr.broadcast();
```javascript
const tr = window.echojslib.echo.createTransaction();

tr.addOperation(echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT, {
tr.addOperation(echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL, {
registrar: '1.2.1',
code: '86be3f80' + '0000000000000000000000000000000000000000000000000000000000000001', // setVariable(uint256)
callee: '1.14.1', // contract id
callee: '1.9.1', // contract id
value: { asset_id: '1.3.0', amount: 0 },
});

Expand Down
59 changes: 5 additions & 54 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h4>Contract</h4>
id="contract-receiver"
name="contract-receiver"
placeholder="callee"
value="1.14.442"
value="1.9.442"
/>
<input
type="text"
Expand Down Expand Up @@ -271,22 +271,6 @@ <h4>Update account</h4>
</div>
<!---->

<!-- Upgrade account -->
<div style="padding-bottom: 10px; border-top: 1px solid #000;">
<h4>Upgrade account</h4>
<div style="padding: 5px 0;">
<input
type="text"
id="upgradeAccount-registrar"
name="upgradeAccount-registrar"
placeholder="registrar"
value="1.2.1204"
/>
<button id="upgradeAccount-click">submit</button>
</div>
<div id="upgradeAccount-info"></div>
</div>

<!-- Sign message -->
<div style="padding-bottom: 10px; border-top: 1px solid #000;">
<h4>Sign message</h4>
Expand Down Expand Up @@ -439,7 +423,7 @@ <h4>Sign message</h4>
$("#contract-click").click(function(e) {
if (!isAccess) return;
const transaction = {
type: window.echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT,
type: window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL,
registrar: jQuery("#contract-registrar")[0].value,
code: jQuery("#contract-code")[0].value,
value: {
Expand All @@ -461,7 +445,7 @@ <h4>Sign message</h4>

const tr = window.echojslib.echo.createTransaction();

tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT, {
tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL, {
registrar: transaction.registrar,
value: {
asset_id: transaction.value.asset_id,
Expand Down Expand Up @@ -494,7 +478,7 @@ <h4>Sign message</h4>
$("#contactCreate-click").click(function (e) {
if (!isAccess) return;
const transaction = {
type: window.echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT,
type: window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE,
registrar: jQuery("#contactCreate-fromAddress")[0].value,
code: jQuery("#contactCreate-code")[0].value,
value: {
Expand All @@ -512,7 +496,7 @@ <h4>Sign message</h4>

const tr = window.echojslib.echo.createTransaction();

tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT, {
tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE, {
registrar: transaction.registrar,
value: {
amount: transaction.value.amount,
Expand Down Expand Up @@ -546,8 +530,6 @@ <h4>Sign message</h4>
if (!isAccess) return;
const transaction = {
registrar: jQuery("#createAccount-registrar")[0].value,
referrer: jQuery("#createAccount-registrar")[0].value,
referrer_percent: 0,
echorand_key: jQuery("#createAccount-echorandKey")[0].value,
name: jQuery("#createAccount-name")[0].value,
active: {
Expand Down Expand Up @@ -629,37 +611,6 @@ <h4>Sign message</h4>
});
});

$("#upgradeAccount-click").click(function (e) {
if (!isAccess) return;
const transaction = {
account_to_upgrade: jQuery("#upgradeAccount-registrar")[0].value,
upgrade_to_lifetime_member: true
};

const tr = window.echojslib.echo.createTransaction();

tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.ACCOUNT_UPGRADE, transaction);

tr.signWithBridge()
.then(result => {
result.broadcast()
.then((res) => {
jQuery("#upgradeAccount-info").html(
`<p>RESULT: ${JSON.stringify(res)}</p>`
);
}).catch(err => {
jQuery("#upgradeAccount-info").html(
`<p>ERROR: ${JSON.stringify(err)}</p>`
);
});
})
.catch(err => {
jQuery("#upgradeAccount-info").html(
`<p>ERROR: ${JSON.stringify(err)}</p>`
);
});
});

$("#signMessage-click").click(function (e) {
if (!isAccess) return;
echojslib.extension.proofOfAuthority('This is example message!', jQuery("#signMessage-account")[0].value)
Expand Down
50 changes: 40 additions & 10 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ let signMessageRequests = [];
const providerNotification = new NotificationManager();
const signNotification = new NotificationManager();

const tabUrls = {};

const connectSubscribe = (status) => {
try {
switch (status) {
Expand Down Expand Up @@ -102,7 +104,7 @@ const getNetwork = async () => {
const createSocket = async (url) => {

if (!url) {
const network = await getNetwork();
const network = await storage.get('current_network') || NETWORKS[0];

({ url } = network);

Expand Down Expand Up @@ -199,10 +201,12 @@ const createNotification = (title = '', message = '') => {
*/
const createAccount = async (name, path) => {
try {
storageSetDraft(FORM_SIGN_UP, 'loading', true);
const network = await getNetwork();
const { error, example } = await validateAccountExist(name);

if (error) {
storageSetDraft(FORM_SIGN_UP, 'loading', false);
storageSetDraft(FORM_SIGN_UP, 'error', { error, example });
emitter.emit('offerName', error, example);
return null;
Expand All @@ -217,8 +221,9 @@ const createAccount = async (name, path) => {
storage.remove(DRAFT_STORAGE_KEY);
} catch (err) {
await emitter.emit('addAccountError', FormatHelper.formatError(err));

storageSetDraft(FORM_SIGN_UP, 'error', { error: FormatHelper.formatError(err), example: '' });
} finally {
storageSetDraft(FORM_SIGN_UP, 'loading', false);
}
return null;

Expand Down Expand Up @@ -261,24 +266,45 @@ const resolveAccounts = async () => {
*/
const onMessage = (request, sender, sendResponse) => {
const { hostname } = urlParse(sender.tab.url);
const { id: tabId } = sender.tab;

request = JSON.parse(JSON.stringify(request));

if (!request.method || !request.appId || request.appId !== APP_ID) return false;

if (request.method === 'closeTab') {
const indexFindRequest = providerRequests.findIndex((rq) => rq.origin === hostname);
if (indexFindRequest === -1) return true;
const indexTabId = providerRequests[indexFindRequest].tabs
.findIndex((id) => id === tabId);
if (indexTabId === -1) return true;
providerRequests[indexFindRequest].cbs.splice(indexTabId, 1);
providerRequests[indexFindRequest].ids.splice(indexTabId, 1);
providerRequests[indexFindRequest].tabs.splice(indexTabId, 1);
return true;
}

if (typeof processedOrigins[hostname] !== 'boolean') {

if (request.method !== 'getAccess') {
sendResponse({ id: request.id, error: 'No access' });
return true;
}

if (providerRequests.find((p) => p.origin === hostname)) {
sendResponse({ id: request.id, error: 'Access has already requested' });
const indexRequest = providerRequests.findIndex((p) => p.origin === hostname);
if (indexRequest !== -1) {
providerRequests[indexRequest].ids.push(request.id);
providerRequests[indexRequest].cbs.push(sendResponse);
providerRequests[indexRequest].tabs.push(tabId);
return true;
}

providerRequests.push({ origin: hostname, id: request.id, cb: sendResponse });
providerRequests.push({
origin: hostname,
tabs: [tabId],
ids: [request.id],
cbs: [sendResponse],
});

setBadge();

Expand Down Expand Up @@ -619,15 +645,16 @@ const onSwitchActiveAccount = (res) => {
* @param {Boolean} status
*/
export const onProviderApproval = (err, id, status) => {
const request = providerRequests.find((r) => String(r.id) === id);
const request = providerRequests.find(({ ids }) => String(ids[0]) === id);

if (!request) {
return;
}

request.cb({ error: err, id: request.id, status });

providerRequests = providerRequests.filter((p) => p.id !== request.id);
request.ids.forEach((rId, index) => request.cbs[index]({ error: err, id: rId, status }));

providerRequests = providerRequests.filter(({ ids }) => ids[0] !== request.ids[0]);
processedOrigins[request.origin] = status;

if (!providerRequests.length) {
Expand Down Expand Up @@ -713,8 +740,8 @@ window.getList = () => requestQueue.map(({ id, data }) => ({ id, options: data }
window.getPrivateKey = () => PrivateKey;
window.getAes = () => aes;
window.Transaction = () => Transaction;
window.getProviderMap = () => providerRequests.reduce((map, { id, origin }) => {
map[id] = origin;
window.getProviderMap = () => providerRequests.reduce((map, { ids: [reqId], origin }) => {
map[reqId] = origin;
return map;
}, {});

Expand All @@ -737,3 +764,6 @@ crypto.on('unlocked', onPinUnlock);
extensionizer.runtime.onInstalled.addListener(onFirstInstall);

extensionizer.browserAction.setBadgeText({ text: 'BETA' });



30 changes: 26 additions & 4 deletions extension/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const extensionizer = require('./extensionizer');
const { APP_ID } = require('../src/constants/GlobalConstants');
const getAccessRequest = {};

/**
* inpage script injection to web page
Expand Down Expand Up @@ -49,14 +50,28 @@ const onResponse = (res, origin = '*') => {
* On Inpage message
* @param event
*/
const onMessage = (event) => {

const { data } = event;
const onMessage = async (event) => {
const { data, origin } = event;

if (data.target !== 'content' || !data.appId || data.appId !== APP_ID) return;

try {
extensionizer.runtime.sendMessage(data, (res) => onResponse(res, event.origin));
if (data.method !== 'getAccess') {
extensionizer.runtime.sendMessage(data, (res) => onResponse(res, event.origin));
return;
}
if (!getAccessRequest[origin]) {
getAccessRequest[origin] = new Promise((resolve) => {
extensionizer.runtime.sendMessage(data, (res) => {
onResponse(res, event.origin);
resolve(res);
});
});
} else {
const result = await getAccessRequest[origin];
result.id = event.data.id;
onResponse(result, event.origin);
}
} catch (err) {
if (err.message.match(/Invocation of form runtime\.connect/) && err.message.match(/doesn't match definition runtime\.connect/)) {
console.error('Connection to background error, please reload the page', err);
Expand All @@ -66,5 +81,12 @@ const onMessage = (event) => {
}
};

window.addEventListener('beforeunload', () => {
extensionizer.runtime.sendMessage({
method: 'closeTab',
appId: APP_ID,
});
});

window.addEventListener('message', onMessage, false);

Loading

0 comments on commit dfaf675

Please sign in to comment.