Skip to content

Instantly share code, notes, and snippets.

View Breta01's full-sized avatar
🤹
All over the place

Bretislav Hajek Breta01

🤹
All over the place
View GitHub Profile
@Breta01
Breta01 / Encryption function.ts
Last active March 11, 2022 14:58
Encryption function used by FELToken
import { encrypt } from '@metamask/eth-sig-util';
const ascii85 = require('ascii85');
function encryptData(publicKey: Buffer, data: Buffer): number[] {
// Returned object contains 4 properties: version, ephemPublicKey, nonce, ciphertext
// Each contains data encoded using base64, version is always the same string
const enc = encrypt({
publicKey: publicKey.toString('base64'),
data: ascii85.encode(data).toString(),
version: 'x25519-xsalsa20-poly1305',
@Breta01
Breta01 / get public key.ts
Last active March 17, 2022 05:15
Requesting the public key from MetaMask
// Account is account address provided as string
// App must have access to the specified account
const account = "0x012...bc"
// Key is returned as base64
const keyB64 = await window.ethereum.request({
method: 'eth_getEncryptionPublicKey',
params: [account],
}) as string;
const publicKey = Buffer.from(keyB64, 'base64');
@Breta01
Breta01 / Using FELToken Final Model.py
Created February 26, 2022 15:39
Example of using final model produced by FELToken.
import numpy as np
import joblib
# Load the model, use the correct path to the model.joblib file
model = joblib.load("model.joblib")
# X should contain the data you want to use for prediction
X = np.array([...])
result = model.predict(X)
@Breta01
Breta01 / Defining Custome Model.py
Created February 26, 2022 15:29
Example of obtaining CID of custom model for feltoken.
from sklearn.linear_model import Ridge
from felt.builder import upload_model
model = Ridge(alpha=0.7)
# Make sure you have WEB3_STORAGE_TOKEN environment variable defined
cid = upload_model(model)
print("CID:", cid)
@Breta01
Breta01 / Example of .env
Created February 1, 2022 04:44
Example of .env file for deployment to polygon
### Private key of account deploying the smart contracts
export PRIVATE_KEY='0xasdfasdfasdfasdfasdfasdfasdfas'
### Infura project ID for communicating with network
export WEB3_INFURA_PROJECT_ID='aaa5aa5a5a5a55555aaa555a5a5555a'
### Polygonscan API token for verifying contracts
export POLYGONSCAN_TOKEN='asdfadfasdfsf'
@Breta01
Breta01 / Changes to brownie-config.yaml
Last active February 1, 2022 04:54
Changes to brownie-config.yaml for deployment on Polygon
# I recommend using .env file for managing secrets
dotenv: .env
# set a custom mnemonic for the development network
networks:
# Polygon
polygon-test:
link_token: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
vrf_coordinator: '0x8C7382F9D8f56b33781fE506E897a4F1e2d17255'
keyhash: '0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4'
@Breta01
Breta01 / .eslintignore
Created January 19, 2022 08:51
Ignore file for linting
node_modules
src/**/*.js
@Breta01
Breta01 / .eslintrc.json
Created January 19, 2022 08:34
Eslint config
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"airbnb",
"plugin:@typescript-eslint/recommended"
],
@Breta01
Breta01 / tsconfig.json
Created January 19, 2022 08:29
TypeScript config file
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
@Breta01
Breta01 / Changes to the file: package.json
Created January 19, 2022 07:56
Following packages should be added to configure TypeScript with React
{
"dependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^17.0.0",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"typescript": "^4.5.4",
...
},
"scripts": {