Skip to content

Instantly share code, notes, and snippets.

View WietseWind's full-sized avatar
⌨️
Focusing

Wietse Wind WietseWind

⌨️
Focusing
View GitHub Profile
@WietseWind
WietseWind / index.mjs
Created June 20, 2024 14:26
Calculate Balance Adjustment on Xahau
import fetch from 'node-fetch'
import { hookStateXLFtoBigNumber } from './xfl.mjs'
// Credits: https://github.com/tequdev/xahau-reward-claim/blob/main/src/app/ClaimReward.tsx
const account = 'rTeLeproT3BVgjWoYrDYpKbBLXPaVMkge'
const RPC_ENDPOINT = 'https://xahau.network'
const toUnixTimestamp = ts => ts + 946684800
@WietseWind
WietseWind / state.mjs
Created June 20, 2024 10:54
Xahau Voucher state
import { getPubKey, xflHexToString } from "./statelib.mjs";
const main = async () => {
console.log(getPubKey(process.argv[2]));
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
@WietseWind
WietseWind / index.mjs
Created June 9, 2024 22:16
DH secp256k1 nodejs
import { createECDH } from 'crypto'
import elliptic from 'elliptic'
import { deriveAddress } from 'ripple-keypairs'
const curve = 'secp256k1'
const secp256k1 = elliptic.ec(curve)
const bytesToHex = a => a.map(byteValue => ('0' + byteValue.toString(16)).slice(-2)).join('')
const getPublic = echdObj => bytesToHex(secp256k1.keyFromPrivate(echdObj.getPrivateKey()).getPublic().encodeCompressed())
@WietseWind
WietseWind / hook.ts
Last active June 4, 2024 13:19
Sample JS Hook - using @xahau/hooks@1.0.7
import {
enableEmit,
getState,
setState,
prepareEmit,
doEmit,
log,
AnyJson,
} from '@xahau/hooks'
@WietseWind
WietseWind / index.mjs
Created June 3, 2024 09:45
256 bits, ED25519 keypair & XRPL account using 10-face dice roll, numbers 0-9 (78 throws)
import accountlib from 'xrpl-accountlib'
import assert from 'assert'
const requiredBits = 256
const requiredThrows = Math.ceil(requiredBits / Math.log2(10))
// Adapted from validator keypair dice tool by RichardAH
// https://github.com/RichardAH/validator-keys-from-dice/blob/main/dice.js
// Random (BAD RANDOM! BAD BAD BAD RANDOM! DO NOT EVER USE THIS!! TESTING PURPOSES ONLY!)
@WietseWind
WietseWind / gen.mjs
Created June 3, 2024 09:29
XRPL Account Generator (ED25519) with 78x 10-face Dice roll
import accountlib from 'xrpl-accountlib'
import elliptic from 'elliptic'
import assert from 'assert'
const ec = new elliptic.eddsa('ed25519')
// Adapted from validator keypair dice tool by RichardAH
// https://github.com/RichardAH/validator-keys-from-dice/blob/main/dice.js
// Random (BAD RANDOM! BAD BAD BAD RANDOM! DO NOT EVER USE THIS!! TESTING PURPOSES ONLY!)
const dicerolls = Array(78).fill().map(r => Math.floor(Math.random() * 10))
@WietseWind
WietseWind / sign-and-submit.mjs
Created May 29, 2024 22:00
Sign & Submit transactions on XRPL and Xahau (testnet, mainnet, multiple nodes)
import { derive, utils, prefilledSignAndSubmit, XrplClient } from "xrpl-accountlib"
const sample = 'xahauTestnet'
const sampleValues = {
xahauTestnet: {
account: derive.familySeed('sstWn1vCjnf6vFT87QHoYJpzYrdu9'),
nodes: [
new XrplClient('wss://xahau-test.net'),
new XrplClient('wss://hooks-testnet-v3.xrpl-labs.com'),
@WietseWind
WietseWind / index.html
Created May 25, 2024 00:40
WASI versions of ESBuild & QuickJS compiler for JS Hooks - fully client side
<! -- Demo here: https://zoq4jb3.dlvr.cloud/index.html -->
<html>
<head>
<style>
pre {
border: 1px solid red;
padding: 10px;
margin: 10px;
}
</style>
@WietseWind
WietseWind / patch.sh
Last active May 10, 2024 14:50
Detect CVE-2024-2961 and mitigage (tested: Ubuntu & Debian & Proxmox hosts) - Host / Docker containers
#!/bin/bash
# Detect CVE-2024-2961 and mitigage (tested: Ubuntu & Debian & Proxmox hosts)
# Wietse Wind 10-05-2024
# Based on the idea from https://raw.githubusercontent.com/mattaperkins/FIX-CVE-2024-2961/main/fix.sh
# ^^ Changes I made: auto detect file (several files eligible instead of one) & create back up of patched file
# Finds the right file and patches
# Safely run again to verify patch
# Run on host:
# curl https://gist.githubusercontent.com/WietseWind/9fe2eda3fece426bf873a4aeb15c4267/raw/patch.sh | bash
@WietseWind
WietseWind / voucher-gen-claim.mjs
Last active April 2, 2024 13:38
Voucher generation & claim
import {
// generate,
derive
} from 'xrpl-accountlib'
import rippleAddressCodec from 'ripple-address-codec'
import {
sign,
verify