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 / 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
]
@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 / 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 / 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'));
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)
// 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 = [
@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
@Anderson-Juhasc
Anderson-Juhasc / index.js
Created February 12, 2025 12:54
Youtube feature of repeat
(function () {
// Wait for the YouTube player to load
function waitForPlayer() {
const player = document.querySelector('.html5-video-player');
if (player) {
setupRepeatFeature(player);
} else {
setTimeout(waitForPlayer, 500);
}
}