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

Commit

Permalink
feat(sdk): fix public key issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joeandrews committed Feb 1, 2020
1 parent 1a4fdd9 commit 2fb9413
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import EthCrypto from 'eth-crypto';
import ClientSubscriptionService from '~/background/services/ClientSubscriptionService';
import userModel from '~/database/models/user';
import {
Expand Down Expand Up @@ -34,23 +33,9 @@ const backgroundResolvers = {
fetchNotesFromBalance: ensureDomainPermission(async (_, args) => ({
notes: await fetchNotesFromBalance(args),
})),
account: ensureDomainPermission(async (_, args) => {
const { spendingPublicKey, ...rest } = await fetchAztecAccount({
address,
});
if (spendingPublicKey) {
const compressedPublicKey = EthCrypto.publicKey.compress(
spendingPublicKey.slice(2),
);
return {
...rest,
spendingPublicKey: `0x${compressedPublicKey}`,
};
}
return {
...rest,
};
}),
account: ensureDomainPermission(async (_, args) => fetchAztecAccount({
address: args.currentAddress,
})),
accounts: ensureDomainPermission(async (_, args, ctx) => ({
accounts: await getAccounts(args, ctx),
})),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import EthCrypto from 'eth-crypto';
import userModel from '~/database/models/user';
import fetchAsset from './utils/fetchAsset';
import fetchAztecAccount from './utils/fetchAztecAccount';
Expand Down Expand Up @@ -27,23 +26,9 @@ const uiResolvers = {
});
return asset;
},
account: async (_, { address }) => {
const { spendingPublicKey, ...rest } = await fetchAztecAccount({
address,
});
if (spendingPublicKey) {
const compressedPublicKey = EthCrypto.publicKey.compress(
spendingPublicKey.slice(2),
);
return {
...rest,
spendingPublicKey: `0x${compressedPublicKey}`,
};
}
return {
...rest,
};
},
account: async (_, { address }) => await fetchAztecAccount({
address,
}),
note: async (_, args) => {
const {
note: noteResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import EthCrypto from 'eth-crypto';
import {
argsError,
} from '~/utils/error';
Expand All @@ -18,15 +17,9 @@ export default async function getAccounts(args) {
})));

accounts = accounts
.map(({ account }) => {
const compressedPublicKey = EthCrypto.publicKey.compress(
account.spendingPublicKey.slice(2),
);
return {
...account,
spendingPublicKey: `0x${compressedPublicKey}`,
};
})
.map(({ account }) => ({
...account,
}))
.filter(a => a);
const onChainAccounts = accounts || [];
const invalidAddresses = addresses
Expand Down
1 change: 0 additions & 1 deletion packages/extension/src/ui/apis/proof/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default async function deposit({
].filter((access, idx, arr) => idx === arr.findIndex(({
address,
}) => address === access.address));

const notes = await createNotes(
noteValues,
spendingPublicKey,
Expand Down
6 changes: 5 additions & 1 deletion packages/extension/src/utils/note/createNote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
note as noteUtils,
} from 'aztec.js';
import EthCrypto from 'eth-crypto';

export default async function createNote(value, publicKey, owner, access) {
let accessArr;
Expand All @@ -17,6 +18,9 @@ export default async function createNote(value, publicKey, owner, access) {
accessArr = [access];
}
}
const compressedPublicKey = EthCrypto.publicKey.compress(
publicKey.slice(2),
);

return noteUtils.create(publicKey, value, accessArr, owner);
return noteUtils.create(`0x${compressedPublicKey}`, value, accessArr, owner);
}

0 comments on commit 2fb9413

Please sign in to comment.