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

Commit

Permalink
Merge branch 'develop' into feat/hot-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeandrews committed Jul 6, 2020
2 parents 49f5d1d + 841bcdc commit a4b981e
Show file tree
Hide file tree
Showing 29 changed files with 2,646 additions and 792 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- This is just a suggested template for bugs, feel free to scrap it if you're just suggesting or requesting a feature>
<!-- This is just a suggested template for bugs, feel free to scrap it if you're just suggesting or requesting a feature -->

## Expected Behaviour

<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ package.json
# packages
packages/contract-addresses/addresses/
packages/contract-artifacts/artifacts/
packages/graph/
packages/documentation/*/apis/
packages/extension/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"lerna": "lerna",
"lint": "yarn wsrun --package $PKG --parallel -c lint",
"prettier": "prettier --config .prettierrc --write '**/*.{js,jsx,json,md}'",
"prettier:ci": "prettier --config .prettierrc --list-different '**/*.{js,jsx,json,md}'",
"prettier:ci": "yarn prettier && prettier --config .prettierrc --list-different '**/*.{js,jsx,json,md}'",
"publish:docs": "yarn wsrun --package $PKG --parallel -c --if has:changed publish:docs",
"rebuild": "run-s clean build",
"script:build:artifacts": "node ./packages/monorepo-scripts/artifacts/build.js",
Expand Down
6 changes: 4 additions & 2 deletions packages/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
},
"description": "AZTEC Protocol documentation based on React Styleguidist",
"scripts": {
"build": "truffle compile --all && styleguidist build && yarn copy",
"build": "truffle compile --all && styleguidist build && yarn copyApis && yarn copyImages",
"clean": "shx rm -rf ./build ./dist ./public || true",
"copy": "find ../extension/src/client/apis -iregex '.(ZkNote|Account|ZkAsset).' -exec cp {} ./public/apis \\;",
"copyApis": "cp -r src/apis public/apis",
"copy:local": "find -E ../extension/src/client/apis -regex '.*(Zk|Account).*' -exec cp {} ./src/apis \\;",
"copyImages": "cp -r ./images ./public",
"generateStyles": "guacamole generateStyles",
"lint": "eslint --ignore-path .eslintignore .",
"start": "yarn styleguide",
Expand Down
131 changes: 131 additions & 0 deletions packages/documentation/src/apis/Account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import {
note as noteUtils,
} from 'aztec.js';
import uniq from 'lodash/uniq';
import Web3Service from '~/client/services/Web3Service';
import ConnectionService from '~/client/services/ConnectionService';
import ApiError from '~/client/utils/ApiError';

const dataProperties = [
'address',
'linkedPublicKey',
'spendingPublicKey',
];

class Account {
constructor(account) {
dataProperties.forEach((key) => {
this[key] = account[key] || '';
});
this.id = account.address;
}

get registered() {
return !!this.linkedPublicKey;
}

/**
*
* @function user.createNote
* @description Description: Create an AZTEC note owned by the user.
*
* @param {Integer} value Value of the note.
*
* @param {[Address]} userAccess Optional array of address that will be granted view access to the note value.
*
* @returns {AztecNote} note An AZTEC note owned by the user.
*
*/
async createNote(value, userAccess = []) {
if (!this.registered) {
throw new ApiError('user.unregistered', {
fn: 'createNote',
});
}

let noteAccess = [];
if (userAccess && userAccess.length) {
({
accounts: noteAccess,
} = await ConnectionService.query(
'users',
{
where: {
address_in: uniq(userAccess),
},
},
`
address
linkedPublicKey
`,
) || {});
}

return noteUtils.create(
this.spendingPublicKey,
value,
noteAccess,
this.address,
);
}

/**
*
* @function user.encryptMessage
* @description Description: Encrypt a message using the user's public key.
*
* @param {String} message Message to be encrypted.
*
* @returns {HexString} encrypted An encrypted message.
*
*/
async encryptMessage(message) {
if (!this.registered) {
throw new ApiError('user.unregistered', {
fn: 'encryptMessage',
});
}

const { encrypted } = await ConnectionService.query(
'encryptMessage',
{
address: this.address,
linkedPublicKey: this.linkedPublicKey,
message,
},
) || {};

return encrypted;
}

/**
*
* @function user.decryptMessage
* @description Description: Decrypt a message using the user's private key.
* This method is available only for current user.
*
* @param {HexString} encrypted An encrypted message.
*
* @returns {String} message The decrypted message.
*
*/
async decryptMessage(message) {
if (this.address !== Web3Service.account.address) {
throw new ApiError('user.logout', {
fn: 'decryptMessage',
});
}

const { decrypted } = await ConnectionService.query(
'decryptMessage',
{
address: this.address,
message,
},
) || {};

return decrypted;
}
}

export default Account;
Loading

0 comments on commit a4b981e

Please sign in to comment.