Skip to content

Instantly share code, notes, and snippets.

View Anderson-Juhasc's full-sized avatar
:octocat:
Looking for work

Anderson Juhasc Anderson-Juhasc

:octocat:
Looking for work
View GitHub Profile
@Anderson-Juhasc
Anderson-Juhasc / nostr-provider.js
Created October 29, 2024 20:50
Nostr NIP-07 with onAccountChanged
// based on: https://github.com/fiatjaf/nos2x/blob/master/extension/nostr-provider.js
window.nostr = {
_requests: {},
_pubkey: null,
_accountChangeCallback: null,
_monitoringInterval: null,
async getPublicKey() {
if (this._pubkey) return this._pubkey
// Need for work on server
import { useWebSocketImplementation } from 'nostr-tools/pool'
import WebSocket from 'ws'
useWebSocketImplementation(WebSocket)
import { generateSecretKey, getPublicKey, finalizeEvent, getEventHash } from 'nostr-tools/pure'
import { SimplePool } from 'nostr-tools/pool'
import { v2 as nip44 } from 'nostr-tools/nip44'
const relayArray = [
const encryptedMessage = await nip04.encrypt(this.prvKey, contact.pubKey, message)
const notificationEvent = {
kind: 4,
pubkey: this.pubKey,
created_at: Math.floor(Date.now() / 1000),
tags: [['p', contact.pubKey]], // Tag the recipient's pubkey
content: encryptedMessage
}
const signedEvent = finalizeEvent(notificationEvent, this.prvKey)
@Anderson-Juhasc
Anderson-Juhasc / bech32.js
Created February 23, 2023 19:31
bitcoinjs-lib and Elliptic.js to generate a bech32 address
const bitcoin = require('bitcoinjs-lib');
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
// Generate a random private key
const privateKey = ec.genKeyPair().getPrivate('hex');
// Convert the private key to a BitcoinJS keypair
const keyPair = bitcoin.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'));
@Anderson-Juhasc
Anderson-Juhasc / index.js
Last active December 10, 2022 09:27
Taproot(p2tr) with BIP38
const { ECPairFactory } = require('ecpair')
const bitcoin = require('bitcoinjs-lib')
const ecurve = require('ecurve')
const secp256k1 = ecurve.getCurveByName('secp256k1')
const schnorr = require('bip-schnorr')
const { bech32, bech32m } = require('bech32')
const bip38 = require('bip38')
const wif = require('wif')
@Anderson-Juhasc
Anderson-Juhasc / constants.js
Last active May 11, 2021 13:21
dogecoin js
module.exports = {
NETWORKS: {
dogecoin: {
messagePrefix: '\x19Dogecoin Signed Message:\n',
bip32: {
public: 0x02facafd,
private: 0x02fac398
},
pubKeyHash: 0x1e,
scriptHash: 0x16,
@Anderson-Juhasc
Anderson-Juhasc / bip84.js
Last active January 2, 2020 18:09
BIP84 - Derives segwit + bech32 addresses from zpub and vpub in javascript: https://www.npmjs.com/package/bip84
const bjs = require('bitcoinjs-lib')
, b58 = require('bs58check')
function BIP84(pub) {
// mainnet
this.pub_types = [
'04b24746', // zpub
'02aa7ed3', // Zpub
]
const isImage = (name, msg, req) => {
let proof = typeof req.files[name] !== "undefined" ? req.files[name] : undefined;
if (!proof) {
throw new Error(msg)
}
switch (proof.type) {
case 'image/jpeg':
return 'image/jpeg';
$breakpoints: "palm" "(max-width: 480px)", "lap" "(min-width: 481px)", "portable" "(max-width: 1023px)", "desk" "(min-width: 1024px)", "desk-wide" "(min-width: 1200px)" !default
=media-query($media-query)
$breakpoint-found: false
@each $breakpoint in $breakpoints
$name: nth($breakpoint, 1)
$declaration: nth($breakpoint, 2)
@if $media-query == $name and $declaration
$breakpoint-found: true
@media only screen and #{$declaration}
const find = ( Model ) => ( query, sort = {} ) =>
Model.find({}).or( query ).sort( sort ).exec()
const findOne = ( Model ) => ( query, populate = '' ) =>
Model.findOne( query ).populate( populate ).exec()
const count = ( Model ) => ( query ) =>
Model.count( query ).exec()
const save = ( Model ) =>