Skip to content

Commit

Permalink
still no luck
Browse files Browse the repository at this point in the history
  • Loading branch information
porco-rosso-j committed Nov 19, 2023
1 parent 698ab46 commit 9b428c7
Show file tree
Hide file tree
Showing 18 changed files with 724 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.16.1
v18.8.0
8 changes: 8 additions & 0 deletions packages/site/gatsby-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { GatsbyConfig } from 'gatsby';

// const proxy = {
// target: 'https://execution.consensys.io',
// changeOrigin: true,
// };

const config: GatsbyConfig = {
// This is required to make use of the React 17+ JSX transform.
jsxRuntime: 'automatic',
Expand All @@ -18,6 +23,9 @@ const config: GatsbyConfig = {
},
},
],
// developMiddleware: (app) => {
// app.use('/aztec3-circuits.wasm', proxy);
// },
};

export default config;
4 changes: 2 additions & 2 deletions packages/site/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const Header = ({
return (
<HeaderWrapper>
<LogoWrapper>
<SnapLogo color={theme.colors.icon.default} size={36} />
<Title>dogecoin-snap</Title>
{/* <SnapLogo color={theme.colors.icon.default} size={36} /> */}
<Title>aztec-snap</Title>
</LogoWrapper>
<RightContainer>
<Toggle
Expand Down
6 changes: 3 additions & 3 deletions packages/site/src/config/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
* Will default to the local hosted snap if no value is provided in environment.
*/
// export const defaultSnapOrigin =
// process.env.SNAP_ORIGIN ?? `local:http://localhost:8080`;
export const defaultSnapOrigin = `local:http://localhost:8080`;
// export const defaultSnapOrigin = `http://localhost:8080/`;
// process.env.SNAP_ORIGIN ?? `local:http://localhost:8081`;
export const defaultSnapOrigin = `local:http://localhost:8081`;
// export const defaultSnapOrigin = `http://localhost:8081/`;
2 changes: 2 additions & 0 deletions packages/site/src/hooks/useAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const useAddress = (isSnapInstalled: boolean) => {
useEffect(() => {
if (isSnapInstalled) {
(async () => {
console.log('getAddress');
const addressResponse = await getAddress();
console.log('addressResponse');
if (addressResponse) {
setAddress(addressResponse);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const Index = () => {
return (
<Container>
<Heading>
Welcome to <Span>dogecoin-snap 🐶</Span>
Welcome to <Span>aztec-snap</Span>
</Heading>
<CardContainer>
{state.error && (
Expand Down Expand Up @@ -161,7 +161,7 @@ const Index = () => {
<Card
fullWidth
content={{
title: 'Your Dogecoin Testnet Address',
title: 'Your AZT Testnet Address',
description: address,
}}
/>
Expand All @@ -170,7 +170,7 @@ const Index = () => {
<Card
fullWidth
content={{
title: 'Your Dogecoin Testnet Balance',
title: 'Your AZT Testnet Balance',
description: `${balance} DOGETEST`,
}}
/>
Expand All @@ -179,7 +179,7 @@ const Index = () => {
<Card
fullWidth
content={{
title: 'Send DOGETEST',
title: 'Send AZT',
description: (
<>
<form onSubmit={handleSendDoge}>
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/utils/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const snapRpcRequest = async <M extends keyof RpcMethodTypes>(
snapId: defaultSnapOrigin,
request: {
// method: `azt_${args.snapRpcMethod}`,
method: `doge_${args.snapRpcMethod as string}`,
method: `azt_${args.snapRpcMethod as string}`,
params: 'params' in args ? args.params : undefined,
},
},
Expand All @@ -82,6 +82,7 @@ const snapRpcRequest = async <M extends keyof RpcMethodTypes>(
* Invoke the "doge_getAddress" RPC method from the snap.
*/
export const getAddress = async () => {
console.log('1');
return snapRpcRequest({
snapRpcMethod: 'getAddress',
});
Expand Down
10 changes: 0 additions & 10 deletions packages/snap/babel.config.json

This file was deleted.

5 changes: 4 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@aztec/aztec.js": "^0.14.2",
"@aztec/circuits.js": "^0.15.0",
"@aztec/foundation": "^0.14.2",
"@aztec/noir-contracts": "^0.14.2",
"@aztec/types": "^0.14.2",
Expand All @@ -39,7 +40,8 @@
"dotenv": "^16.1.4",
"envify": "^4.1.0",
"stream-browserify": "^3.0.0",
"tty-browserify": "^0.0.1"
"tty-browserify": "^0.0.1",
"webpack-browser-plugin": "^1.0.20"
},
"devDependencies": {
"@babel/core": "^7.23.3",
Expand Down Expand Up @@ -69,6 +71,7 @@
"eslint-plugin-jsdoc": "^39.2.9",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"http-proxy-middleware": "^2.0.6",
"prettier": "^2.2.1",
"prettier-plugin-packagejson": "^2.2.11",
"resolve-typescript-plugin": "^2.0.1",
Expand Down
12 changes: 12 additions & 0 deletions packages/snap/service-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line import/unambiguous
self.addEventListener('fetch' as any, (event: FetchEvent) => {
// Your fetch event handling logic here
if (
event.request.url === 'https://execution.consensys.io/aztec3-circuits.wasm'
) {
// Respond with the local wasm file
event.respondWith(
fetch('/node_modules/@aztec/circuits.js/resources/aztec3-circuits.wasm'),
);
}
});
20 changes: 12 additions & 8 deletions packages/snap/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// import path, { dirname, resolve } from 'path';
import { resolve } from 'path';
import type { SnapConfig } from '@metamask/snaps-cli';
import { merge } from '@metamask/snaps-cli';
// import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';
// eslint-disable-next-line import/default
// import CopyWebpackPlugin from 'copy-webpack-plugin';
import { EsbuildPlugin } from 'esbuild-loader';
// import { dirname, resolve } from 'path';
import { resolve } from 'path';
// import browserPlugin from 'webpack-browser-plugin';

// import ResolveTypeScriptPlugin from 'resolve-typescript-plugin';
// import type { Configuration } from 'webpack';

Expand All @@ -24,9 +27,11 @@ const config: SnapConfig = {
// type: 'commonjs',
// },
},

server: {
enabled: true,
port: 8080,
// root: 'src',
port: 8081,
},
experimental: {
wasm: true,
Expand Down Expand Up @@ -89,11 +94,10 @@ const config: SnapConfig = {
// new CopyWebpackPlugin({
// patterns: [
// {
// from: `${dirname(require.resolve(`@aztec/circuits.js`)).replace(
// /\/dest$/u,
// '',
// )}/resources/aztec3-circuits.wasm`,
// to: 'aztec3-circuits.wasm',
// from: `${path
// .dirname(require.resolve(`@aztec/circuits.js`))
// .replace(/\/dest$/u, '')}/resources/aztec3-circuits.wasm`,
// to: 'public/aztec3-circuits.wasm', // Adjust the destination directory
// },
// ],
// }),
Expand Down
3 changes: 1 addition & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "ttEDlwcB4ikmtjX9uejfS98WSNdegr5OPte/5u7oqQE=",
"shasum": "Z4e7kQKM7TTk2DUGjooVKmMq9r5HbK1j47Cm/9aLkyo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
"iconPath": "images/icon.svg",
"packageName": "@ziad-saab/dogecoin-snap",
"registry": "https://registry.npmjs.org/"
}
Expand Down
44 changes: 0 additions & 44 deletions packages/snap/src/contract-types/Voting.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { OnRpcRequestHandler } from '@metamask/snaps-types';
// } from './rpc';
import { getAddress, getAztBalance, getTx, makeTransaction } from './pxe';
import { assertIsMakeTransactionParams } from './types';
// eslint-disable-next-line import/no-unassigned-import
import './worker-registration';

// export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
// switch (request.method) {
Expand Down
60 changes: 35 additions & 25 deletions packages/snap/src/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { copyable, divider, heading, panel, text } from '@metamask/snaps-ui';
// import { TokenContract } from '@aztec/noir-contracts';
// import { getECDSAAccount } from './account';
// import { MakeTransactionParams } from './pxe-types';
import {
createPXEClient,
GrumpkinScalar,
Fr,
SingleKeyAccountContract,
SchnorrAccountContract,
AccountManager,
} from '@aztec/aztec.js';

import { MakeTransactionParams } from './types';
import { PXE_URL } from './constants';
import { VotingContract } from './contract-types/Voting';
Expand All @@ -18,35 +27,36 @@ import { VotingContract } from './contract-types/Voting';
* This demo wallet uses a single account/address.
*/

const pk = '0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281';

export const getAddress = async (): Promise<string> => {
const aztec = await import('@aztec/aztec.js');
// const encryptionPrivateKey = new aztec.GrumpkinScalar(new aztec.Fr(pk));
// console.log('1');
const pxe = await aztec.createPXEClient(PXE_URL);
// const pk = 0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281;
// const encryptionPrivateKey = new GrumpkinScalar(new Fr(pk).fromS);
const encryptionPrivateKey: GrumpkinScalar = GrumpkinScalar.random();
console.log('encryptionPrivateKey: ', encryptionPrivateKey);
const pxe = await createPXEClient(PXE_URL);
console.log('pxe: ', pxe);
// const accountContract = new aztec.SingleKeyAccountContract(
// encryptionPrivateKey,
// );
// console.log('3');
// const accountManager = new aztec.AccountManager(
// pxe,
// encryptionPrivateKey,
// accountContract,
// );
// console.log('4');

console.log('node info: ', await pxe.getNodeInfo());
const accountContract = new SchnorrAccountContract(encryptionPrivateKey);
console.log('accountContract: ', accountContract);
const accountManager = new AccountManager(
pxe,
encryptionPrivateKey,
accountContract,
);
console.log('4');
console.log('accountManager: ', accountManager);

// const wallet = await accountManager.getWallet();
// console.log('5');
// const votingContract = await VotingContract.at(
// '0x1254268ac4d842d5c3acd9e555015b13e2785a3e51b3272cd6578534e59d1c87',
// wallet,
// );
// console.log('6');
// const adminAddr = await votingContract.methods.admin().view();
// return adminAddr.toString();
return '';
const wallet = await accountManager.waitDeploy();
console.log('5');
console.log('wallet: ', wallet);
const votingContract = await VotingContract.at(
'0x149a9593f1ca604b7aeb9c8d7732b872b84b358ac765e4a03af2093d2cb6da0e',
wallet,
);
console.log('6');
const adminAddr = await votingContract.methods.admin().view();
return adminAddr.toString();
};

export const getTx = async (): Promise<any[]> => {
Expand Down
18 changes: 18 additions & 0 deletions packages/snap/src/worker-registration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line import/unambiguous
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
// Code that references navigator here

if ('serviceWorker' in window.navigator) {
window.navigator.serviceWorker
.register('../service-worker.ts')
.then((registration: ServiceWorkerRegistration) => {
console.log(
'Service Worker registered with scope:',
registration.scope,
);
})
.catch((error: Error) => {
console.error('Service Worker registration failed:', error);
});
}
}
1 change: 1 addition & 0 deletions packages/snap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"compilerOptions": {
"composite": true,
"resolveJsonModule":true,
"lib": ["webworker", "dom"],
"baseUrl": "./",
"experimentalDecorators": true,
}
Expand Down
Loading

0 comments on commit 9b428c7

Please sign in to comment.