Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #526 from AztecProtocol/feat/hot-fixes
Browse files Browse the repository at this point in the history
 feat(sdk): return signature as well as proof with returnproof flag
  • Loading branch information
ArnSch authored Jul 16, 2020
2 parents 9aa5691 + 6bbdb23 commit fed09a1
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const getAccountMapping = async ({
user: {
account,
error,
},
} = {},
} = await query(request, userQuery(`
address
linkedPublicKey
Expand All @@ -208,6 +208,7 @@ const getAccountMapping = async ({
}
}));


accounts.forEach((account) => {
accountMapping[account.address] = account;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ export default async function prove(query, connection) {
data: {
args,
},
sender,
} = query;
const {
proofType,
returnProof,
} = args;

let returnData = {};
if (!returnProof) {
if (sender === 'WEB_CLIENT') {
returnData = await triggerProofUi(query, connection);
} else {
switch (proofType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const fetchOutputNotes = ({ proofData }) => {
const fetchOutputNotes = ({
proofData,
proof,
signature,
signature2,
}) => {
const {
outputNotes,
remainderNote,
Expand All @@ -18,16 +23,28 @@ const fetchOutputNotes = ({ proofData }) => {
noteHash,
value,
})),
proof,
signature,
signature2,

};
};

const returnProof = ({ proof, signature, signature2 }) => ({
proof,
signature,
signature2,
});

export default {
DEPOSIT_PROOF: [
fetchOutputNotes,
returnProof,
],
WITHDRAW_PROOF: [],
TRANSFER_PROOF: [
fetchOutputNotes,
returnProof,
],
CREATE_NOTE_FROM_BALANCE_PROOF: [
(data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class SyncManager {
constructor() {
this.config = {
syncInterval: 5000, // ms
blocksPerRequest: 50, // ~ per 3 months (~6000 per day)
precisionDelta: 10, //
maxNumberOfAttempts: 5,
};
this.syncConfig = undefined;
this.networks = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class NotesSyncManagerFactory {
managersByNetworks = {};

config = {
blocksPerRequest: 5307319, // ~ per 3 months (~6000 per day)
blocksPerRequest: 100, // ~ per 3 months (~6000 per day)
precisionDelta: 10, //
networkId: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const infuraLimitError = {
message: 'query returned more than 10000 results',
};

const isInfuraLimitError = error => error && error.code === infuraLimitError.code;

const uriTooLong = {
code: -32603,
};
// eslint-disable-next-line
const isInfuraLimitError = error => error && error.code === infuraLimitError.code || error.code === uriTooLong.code;

const SYNCING_STATUS = {
ACTIVE: 'ACTIVE',
Expand All @@ -30,7 +35,7 @@ const SYNCING_STATUS = {
class SyncManager {
constructor() {
this.config = {
blocksPerRequest: 540000, // ~ per 3 months (~6000 per day)
blocksPerRequest: 6000 * 30, // ~ per 3 months (~6000 per day)
precisionDelta: 10, //
maxNumberOfAttempts: 5,
networkId: null,
Expand Down Expand Up @@ -134,7 +139,7 @@ class SyncManager {
lastSyncedBlock,
assets,
progressCallbacks,
retriedNumber = 0,
retriedNumber = 5,
} = options;

const syncAddress = this.addresses.get(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ class Watcher {

return subscription;
}

handleFetchError = (error) => {
errorLog('Failed to sync CreateNote / UpdateMetadata / DestroyNote with web3.', error);
if (process.env.NODE_ENV === 'development') {
this.paused = true;
}
};
}

export default Watcher;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Web3 from 'web3';
import Web3Service from '~/helpers/Web3Service';
import {
ZkAsset,
} from '~/config/contracts';
import decodeNoteLogs from './helpers/decodeNoteLogs';
import { getProviderUrl } from '~/utils/network';

export default async function fetchNotes({
owner,
Expand All @@ -16,7 +18,9 @@ export default async function fetchNotes({
ZkAsset.events.updateNoteMetaData,
],
} = {}) {
const { abi, getPastLogs } = Web3Service.eth;
// TODO require network selection
const provider = new Web3.providers.HttpProvider(getProviderUrl(Web3Service.networkId));
const { abi, getPastLogs } = new Web3(provider).eth;

const eventsTopics = events
.map(e => ZkAsset.config.abi.find(({ name, type }) => name === e && type === 'event'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Web3 from 'web3';
import Web3Service from '~/helpers/Web3Service';
import {
ZkAsset,
Expand All @@ -6,6 +7,7 @@ import {
errorLog,
} from '~/utils/log';
import decodeNoteLogs from './helpers/decodeNoteLogs';
import { getProviderUrl } from '~/utils/network';

const subscribe = async ({
owner,
Expand All @@ -18,10 +20,8 @@ const subscribe = async ({
return null;
}

const {
abi,
subscribe: subscribeOn,
} = Web3Service.eth;
const provider = getProviderUrl(Web3Service.networkId, true);
const { abi, subscribe: subscribeOn } = new Web3(provider).eth;

const eventsTopics = [
ZkAsset.events.createNote,
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/background/tasks/acceptConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
errorLog,
} from '~/utils/log';
import Connection from '../utils/connection';
import migrateIndexedDB from './migrateIndexedDB';
// import migrateIndexedDB from './migrateIndexedDB';
import setupNetworkConfig from './setupNetworkConfig';

const resourceOrigin = getResourceUrl('origin');
Expand All @@ -36,7 +36,7 @@ export default function acceptConnection() {

if (clientProfile) {
try {
await migrateIndexedDB();
// await migrateIndexedDB();
networkConfig = await setupNetworkConfig(clientProfile);
connection.initUi();
} catch (e) {
Expand Down
14 changes: 6 additions & 8 deletions packages/extension/src/client/apis/ZkAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export default class ZkAsset {
returnProof,
sender,
publicOwner,
...rest
} = {}) => {
if (!this.linkedTokenAddress) {
throw new ApiError('zkAsset.private', {
Expand Down Expand Up @@ -288,6 +289,7 @@ export default class ZkAsset {
}

return {
...rest,
success,
outputNotes,
proof,
Expand Down Expand Up @@ -330,6 +332,7 @@ export default class ZkAsset {
inputNoteHashes,
returnProof,
sender,
...rest
} = {}) => {
if (!this.linkedTokenAddress) {
throw new ApiError('zkAsset.private', {
Expand Down Expand Up @@ -367,6 +370,7 @@ export default class ZkAsset {
}

return {
...rest,
success,
proof,
};
Expand Down Expand Up @@ -431,6 +435,7 @@ export default class ZkAsset {
success,
outputNotes,
proofData,
...rest
} = await ConnectionService.query(
'constructProof',
{
Expand All @@ -447,17 +452,10 @@ export default class ZkAsset {
},
);

let proof;
if (proofData) {
proof = proofData
? await recoverJoinSplitProof(proofData)
: null;
}

return {
...rest,
success,
outputNotes,
proof,
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/config/database.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const version = 1;
export const version = 2;
export const sdkSettingDbName = 'aztec-sdk';
export const networkDbPrefix = 'aztec_network';
3 changes: 2 additions & 1 deletion packages/extension/src/config/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const infuraProjectId = '09c4eed231c840d5ace14ba5389a1a7c';

export const infuraProviderUrlPattern = 'wss://{networkName}.infura.io/ws/v3/{projectId}';
export const infuraHttpProviderUrlPattern = 'https://{networkName}.infura.io/v3/{projectId}';
export const infuraWsProviderUrlPattern = 'wss://{networkName}.infura.io/ws/v3/{projectId}';

export const defaultProviderUrl = 'ws://localhost:8545';
2 changes: 1 addition & 1 deletion packages/extension/src/config/supportsPermitSignature.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
'0x6B175474E89094C44Da98b954EedeAC495271d0F': true,
// '0x6B175474E89094C44Da98b954EedeAC495271d0F': true,
};
8 changes: 7 additions & 1 deletion packages/extension/src/ui/pages/Send.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Send = ({
numberOfOutputNotes,
inputNoteHashes,
userAccess,
returnProof,
}) => {
const fetchInitialData = async () => {
const gsnConfig = await getGSNConfig();
Expand All @@ -31,7 +32,10 @@ const Send = ({
const {
address: currentAddress,
} = currentAccount;
const steps = isGSNAvailable ? sendSteps.gsn : sendSteps.metamask;
let steps = isGSNAvailable ? sendSteps.gsn : sendSteps.metamask;
if (returnProof) {
steps = sendSteps.returnProof;
}
const sender = proxyContract;

const asset = await makeAsset(assetAddress);
Expand Down Expand Up @@ -77,13 +81,15 @@ Send.propTypes = {
numberOfOutputNotes: PropTypes.number,
inputNoteHashes: PropTypes.arrayOf(PropTypes.string),
userAccess: PropTypes.arrayOf(PropTypes.string),
returnProof: PropTypes.bool,
};

Send.defaultProps = {
numberOfInputNotes: emptyIntValue,
numberOfOutputNotes: emptyIntValue,
inputNoteHashes: [],
userAccess: [],
returnProof: false,
};

export default Send;
4 changes: 4 additions & 0 deletions packages/extension/src/ui/steps/createNoteFromBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const stepSendViaGSN = {
};

export default {
returnProof: {
stepApprove,
stepSign,
},
gsn: [
stepApprove,
stepSign,
Expand Down
4 changes: 4 additions & 0 deletions packages/extension/src/ui/steps/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const stepSendViaGSN = {
};

export default {
returnProof: [
stepApprove,
stepSignNotes,
],
gsn: [
stepApprove,
stepSignNotes,
Expand Down
4 changes: 4 additions & 0 deletions packages/extension/src/ui/steps/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const stepSendViaGSN = {
};

export default {
returnProof: [
stepApprove,
stepSignNotes,
],
gsn: [
stepApprove,
stepSignNotes,
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/utils/Web3Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class Web3Service {
method: gsnContract.methods[methodName],
fromAddress: signingInfo.address,
args,
gasPrice: gasPrice ? gasPrice * 2 : 18000000000, // set gas price 100% higher than last few blocks median to ensure we get in the block
gasPrice: gasPrice ? gasPrice * 1 : 18000000000, // set gas price 100% higher than last few blocks median to ensure we get in the block
web3,
});
},
Expand Down
7 changes: 4 additions & 3 deletions packages/extension/src/utils/network/getProviderUrl.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import networks from '~/config/networks';
import {
infuraProjectId,
infuraProviderUrlPattern,
infuraHttpProviderUrlPattern,
infuraWsProviderUrlPattern,
defaultProviderUrl,
} from '~/config/provider';
import {
formatStrPattern,
} from '~/utils/format';

export default function getProviderUrl(networkId, projectId = infuraProjectId) {
export default function getProviderUrl(networkId, ws = false, projectId = infuraProjectId) {
const networkKey = Object.keys(networks)
.find(name => networks[name].id === networkId);
const network = networks[networkKey];
Expand All @@ -20,7 +21,7 @@ export default function getProviderUrl(networkId, projectId = infuraProjectId) {
networkName,
} = network;

return formatStrPattern(infuraProviderUrlPattern, {
return formatStrPattern(ws ? infuraWsProviderUrlPattern : infuraHttpProviderUrlPattern, {
networkName: networkName.toLowerCase(),
projectId,
});
Expand Down

0 comments on commit fed09a1

Please sign in to comment.