Skip to content

Instantly share code, notes, and snippets.

View gregsantos's full-sized avatar

Greg Santos gregsantos

View GitHub Profile
@gregsantos
gregsantos / fcl.d.ts
Created December 15, 2022 17:12
Type defs for FCL
/* eslint-disable @typescript-eslint/no-explicit-any */
// Type definitions for @onflow/fcl 1.3.0
// Project: https://github.com/onflow/fcl-js
declare module "@onflow/six-create-account" {
let template: any;
}
declare global {
interface Window {
fcl: any;
const fcl = require("@onflow/fcl")
const {TransactionAuthorizer} = require("@freshmint/core")
const {
HashAlgorithm,
InMemoryECSigner,
SignatureAlgorithm,
InMemoryECPrivateKey,
} = require("@freshmint/core/crypto")
const PRIVATE_KEY_HEX =
@gregsantos
gregsantos / sign-verify.js
Created October 4, 2022 16:04
ECDSA in JavaScript: secp256k1-based sign / verify / recoverPubKey
let elliptic = require('elliptic');
let sha3 = require('js-sha3');
let ec = new elliptic.ec('secp256k1');
// let keyPair = ec.genKeyPair();
let keyPair = ec.keyFromPrivate("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a");
let privKey = keyPair.getPrivate("hex");
let pubKey = keyPair.getPublic();
console.log(`Private key: ${privKey}`);
console.log("Public key :", pubKey.encode("hex").substr(2));
const {randomBytes} = require("crypto")
const secp256k1 = require("secp256k1")
// or require('secp256k1/elliptic')
// if you want to use pure js implementation in node
// generate message to sign
// message should have 32-byte length, if you have some other length you can hash message
// for example `msg = sha256(rawMessage)`
const msg = randomBytes(32)
@gregsantos
gregsantos / obj-validation-shallow.js
Last active September 18, 2022 19:15
obj-validation-shallow
const isFn = v => typeof v === "function"
const isString = v => typeof v === "string"
function meta(meta) {
return pipe([
ix => {
ix.meta = meta
return Ok(ix)
},
])
@gregsantos
gregsantos / getTxHash.js
Created October 27, 2021 21:16
get transaction hash before send
let txIdCalculated = null
const getTxHash = async () => {
const txIdFromChain = await sdk.decode(
await sdk.send(
await sdk.resolve(
await sdk.build([
sdk.transaction`transaction(msg: String) { prepare(acct: AuthAccount) {} execute { log(msg) } }`,
sdk.args([sdk.arg("Hello, Flow!", t.String)]),
sdk.payer(fcl.currentUser().authorization),
sdk.proposer(fcl.currentUser().authorization),
@gregsantos
gregsantos / account-proof.js
Created October 26, 2021 18:49
account-proof
// Authentication Proof Service
{
"f_type": "Service",
"f_vsn": "1.0.0",
"type": "account-proof",
"method": "DATA",
"uid": "fcl-dev-wallet#account-proof",
"data": {
"f_type": "account-proof",
"f_vsn": "1.0.0",
name: CICD
# Triggers the workflow on push to master
on:
push:
branches:
- master
jobs:
@gregsantos
gregsantos / async getData.js
Created June 25, 2020 19:11
async function to hit API
export async function getData() {
async function userData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'GET', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',

Walk-Thru of Array Iterator Methods

Intro

JavaScript Arrays have lots of helpful built-in methods.

These methods allow you to write more declarative/functional code as opposed to imperative code.