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

Commit a75b332

Browse files
authored
Merge pull request #442 from AztecProtocol/feat-doc-examples
Add documentation - SDK, aztec.js, starterkits, specification
2 parents b195855 + faf3c50 commit a75b332

File tree

156 files changed

+10879
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+10879
-204
lines changed

.circleci/config.yml

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
version: 2.0
1+
version: 2.1
2+
3+
orbs:
4+
aws-cli: circleci/[email protected]
25

36
jobs:
47
build:
@@ -55,6 +58,7 @@ jobs:
5558
- ~/repo/packages/contract-artifacts/lib
5659
- ~/repo/packages/note-access/lib
5760
- ~/repo/packages/dev-utils/lib
61+
- ~/repo/packages/documentation/public
5862
- ~/repo/packages/typed-data/lib
5963
lint:
6064
working_directory: ~/repo
@@ -106,7 +110,7 @@ jobs:
106110
- run:
107111
name: "Orchestrate Artifacts"
108112
command: yarn script:orchestrate:artifacts
109-
docs:
113+
docs-aztecjs:
110114
working_directory: ~/repo
111115
docker:
112116
- image: circleci/node:10.15.3
@@ -127,7 +131,24 @@ jobs:
127131
- run:
128132
name: "Publish Docs"
129133
command: yarn publish:docs
130-
134+
deploy-docs:
135+
working_directory: ~/repo
136+
executor: aws-cli/default
137+
steps:
138+
- aws-cli/setup:
139+
profile-name: circleci
140+
- restore_cache:
141+
keys:
142+
- repo-{{ .Environment.CIRCLE_SHA1 }}
143+
- run:
144+
name: Delete old docs
145+
command: aws s3 rm s3://${AWS_DOCS_BUCKET} --recursive
146+
- run:
147+
name: Upload new docs
148+
command: aws s3 cp ./packages/documentation/public s3://${AWS_DOCS_BUCKET} --recursive --metadata-directive REPLACE --cache-control "max-age=3600" --acl public-read
149+
- run:
150+
name: Clear cache
151+
command: aws cloudfront create-invalidation --distribution-id ${AWS_DOCS_CLOUDFRONT} --paths "/*"
131152
release:
132153
working_directory: ~/repo
133154
docker:
@@ -178,14 +199,24 @@ workflows:
178199
branches:
179200
only:
180201
- develop
181-
- docs:
202+
- docs-aztecjs:
182203
requires:
183204
- lint
184205
- test
185206
filters:
186207
branches:
187208
only:
188209
- develop
210+
- deploy-docs:
211+
requires:
212+
- lint
213+
- test
214+
context: aws
215+
- test
216+
filters:
217+
branches:
218+
only:
219+
- develop
189220
- release:
190221
requires:
191222
- lint

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727

2828
## Documentation :books:
2929

30-
There are two key sources of documentation:
30+
All AZTEC documentation is available on the documentation website: https://docs.aztecprotocol.com
3131

32-
1. Protocol specification: https://github.com/AztecProtocol/specification
33-
2. Our client side SDK: https://docs.aztecprotocol.com
32+
This contains docs for the:
33+
34+
- SDK
35+
- aztec.js
36+
- Starter kits, demos and code examples
37+
- Protocol specification
3438

3539
## Packages :package:
3640

packages/documentation/.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

packages/documentation/.eslintignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ignored directories
2+
*/node_modules/*
3+
dist/*
4+
fonts/*
5+
*/build/*
6+
public/*
7+
src/*
8+
9+
# ignored extensions
10+
**/*.json
11+
**/*.css
12+
**/*.scss
13+
**/*.md
14+
**/*.ejs
15+
**/*.ico
16+
**/*.svg
17+
**/*.lock
18+
**/*.log
19+
**/*.yml

packages/documentation/.eslintrc.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = {
2+
extends: ['airbnb', 'prettier'],
3+
parserOptions: {
4+
ecmaFeatures: {
5+
jsx: true,
6+
},
7+
sourceType: 'module',
8+
},
9+
env: {
10+
browser: true,
11+
mocha: true,
12+
node: true,
13+
es6: true,
14+
jest: true,
15+
},
16+
plugins: ['react', 'jsx-a11y', 'import'],
17+
settings: {
18+
'import/resolver': {
19+
alias: {
20+
map: [['src', './src']],
21+
extensions: ['.jsx', '.js', '.scss'],
22+
},
23+
},
24+
},
25+
overrides: [
26+
{
27+
files: ['*.spec.js', '*.spec.jsx'],
28+
rules: {
29+
'no-unused-expressions': 0,
30+
},
31+
},
32+
],
33+
rules: {
34+
'react/jsx-curly-brace-presence': 'off',
35+
'react/jsx-indent': 'off',
36+
'react/jsx-indent-props': 'off',
37+
'react/jsx-wrap-multilines': 'off',
38+
'react/destructuring-assignment': 'off',
39+
'react/forbid-prop-types': 'off',
40+
'import/no-unresolved': [
41+
'error',
42+
{
43+
ignore: ['^~contracts/'],
44+
},
45+
],
46+
'import/no-named-as-default': 'off',
47+
'import/no-named-as-default-member': 'off',
48+
'no-param-reassign': 'off',
49+
'no-console': 'off',
50+
},
51+
};

packages/documentation/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
.env
4+
5+
public

packages/documentation/.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.editorconfig
2+
.eslintignore
3+
.eslintrc.js
4+
.gitignore
5+
babel.config.js
6+
styleguide.config.js
7+
webpack.config.js
8+
/scripts
9+
/styleguide

packages/documentation/.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"arrowParens": "always",
3+
"printWidth": 130,
4+
"singleQuote": true,
5+
"tabWidth": 2,
6+
"trailingComma": "all"
7+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
browsers: ['last 2 versions'],
8+
},
9+
},
10+
],
11+
'@babel/preset-react',
12+
],
13+
plugins: [
14+
[
15+
'@babel/transform-runtime',
16+
{
17+
regenerator: true,
18+
},
19+
],
20+
'@babel/plugin-proposal-class-properties',
21+
'@babel/plugin-proposal-object-rest-spread',
22+
],
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pragma solidity >=0.5.0 <0.6.0;
2+
3+
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
4+
5+
/**
6+
* @title ERC20Mintable
7+
* @dev ERC20 minting logic
8+
* Sourced from OpenZeppelin and thoroughly butchered to remove security guards.
9+
* Anybody can mint - STRICTLY FOR TEST PURPOSES
10+
*/
11+
contract ERC20Mintable is ERC20 {
12+
/**
13+
* @dev Function to mint tokens
14+
* @param _to The address that will receive the minted tokens.
15+
* @param _value The amount of tokens to mint.
16+
* @return A boolean that indicates if the operation was successful.
17+
*/
18+
function mint(address _to, uint256 _value) public returns (bool) {
19+
_mint(_to, _value);
20+
return true;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
pragma solidity >=0.5.0 <0.6.0;
2+
3+
/**
4+
* @title ETHFaucet implementation
5+
* @author AZTEC
6+
* Copyright Spilbury Holdings Ltd 2019. All rights reserved.
7+
**/
8+
9+
import "@openzeppelin/upgrades/contracts/Initializable.sol";
10+
11+
import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";
12+
import "@openzeppelin/contracts-ethereum-package/contracts/cryptography/ECDSA.sol";
13+
14+
15+
contract AccountRegistry {
16+
mapping(address => bytes) public accountMapping;
17+
}
18+
19+
20+
21+
contract EthFaucet is Initializable, GSNRecipient {
22+
mapping(address =>uint256) public faucetMapping;
23+
address trustedSigner;
24+
address accountRegistryAddress;
25+
event GSNTransactionProcessed(bytes32 indexed signatureHash, bool indexed success, uint actualCharge);
26+
27+
constructor(address _accountRegistryAddress, address _trustedAddress) public {
28+
accountRegistryAddress = _accountRegistryAddress;
29+
initialize(_trustedAddress);
30+
}
31+
32+
/**
33+
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
34+
*/
35+
function initialize(address _trustedSigner) public initializer {
36+
require(_trustedSigner != address(0), "GSNRecipientSignature: trusted signer is the zero address");
37+
trustedSigner = _trustedSigner;
38+
39+
GSNRecipient.initialize();
40+
}
41+
42+
// @dev allow users to request 0.1eth every 24 hours
43+
function requestTestEth(address _recipient) public payable {
44+
// bytes memory linkedPublicKey = AccountRegistry(accountRegistryAddress).accountMapping(_recipient);
45+
46+
// require(linkedPublicKey.length > 0, 'Please register this address with the SDK to request ETH');
47+
require(faucetMapping[_recipient] + 1 days <= block.timestamp, 'Greedy please wait 24hours between requests');
48+
49+
faucetMapping[_recipient] = block.timestamp;
50+
51+
address payable recipient = address(uint160(_recipient)); // Correct since Solidity >= 0.5.0
52+
53+
_recipient.call.value(100000000000000000).gas(20317)("");
54+
}
55+
56+
57+
function () external payable {
58+
59+
}
60+
61+
62+
using ECDSA for bytes32;
63+
64+
uint256 constant private RELAYED_CALL_REJECTED = 11;
65+
66+
enum GSNRecipientSignatureErrorCodes {
67+
INVALID_SIGNER,
68+
INVALID_TIMESTAMP
69+
}
70+
71+
72+
/**
73+
* @dev Return this in acceptRelayedCall to impede execution of a relayed call. No fees will be charged.
74+
*/
75+
function _rejectRelayedCall(uint256 errorCode, bytes memory context) internal pure returns (uint256, bytes memory) {
76+
return (RELAYED_CALL_REJECTED + errorCode, context);
77+
}
78+
79+
/**
80+
* @dev Ensures that only transactions with a trusted signature can be relayed through the GSN.
81+
*/
82+
function acceptRelayedCall(
83+
address relay,
84+
address from,
85+
bytes calldata encodedFunction,
86+
uint256 transactionFee,
87+
uint256 gasPrice,
88+
uint256 gasLimit,
89+
uint256 nonce,
90+
bytes calldata approvalData,
91+
uint256
92+
)
93+
external
94+
view
95+
returns (uint256, bytes memory context)
96+
{
97+
(
98+
uint256 maxTimestamp,
99+
bytes memory signature
100+
) = abi.decode(approvalData, (uint256, bytes));
101+
102+
bytes memory blob = abi.encodePacked(
103+
relay,
104+
from,
105+
encodedFunction,
106+
transactionFee,
107+
gasPrice,
108+
gasLimit,
109+
nonce, // Prevents replays on RelayHub
110+
getHubAddr(), // Prevents replays in multiple RelayHubs
111+
address(this), // Prevents replays in multiple recipients
112+
maxTimestamp // Prevents sends tx after long perion of time
113+
);
114+
context = abi.encode(signature);
115+
116+
if (keccak256(blob).toEthSignedMessageHash().recover(signature) == trustedSigner) {
117+
if (block.timestamp > maxTimestamp) {
118+
return _rejectRelayedCall(uint256(GSNRecipientSignatureErrorCodes.INVALID_TIMESTAMP), context);
119+
}
120+
return _approveRelayedCall(context);
121+
} else {
122+
return _rejectRelayedCall(uint256(GSNRecipientSignatureErrorCodes.INVALID_SIGNER), context);
123+
}
124+
}
125+
126+
127+
function _preRelayedCall(bytes memory) internal returns (bytes32) {
128+
// solhint-disable-previous-line no-empty-blocks
129+
}
130+
131+
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal {
132+
(bytes memory approveData) = abi.decode(context, (bytes));
133+
emit GSNTransactionProcessed(keccak256(approveData), success, actualCharge);
134+
}
135+
136+
}
137+

0 commit comments

Comments
 (0)