wietsewind's notebooks

  • XRPL JSON RPC - /wietsewind/xrpl-json-rpc
    Last edited a month ago
    const fetch = require('node-fetch') const testnet = true const endpoint = testnet ? 'https://testnet-rpc.xrpl-labs.com' : 'https://xrplcluster.com' const command = { "method": "account_tx", "params": [ { "account": "rXUMMaPpZqPutoRszR29jtC8amWq3APkx", "limit": 2 } ] } const call = await fetch(endpoint, { method: 'POST', body: JSON.stringify(command) }) const data = await call.json() console.log(data)
  • Get GH XRPL Tx Types - /wietsewind/get-gh-xrpl-tx-types
    Last edited 2 months ago
    const Fetch = require('node-fetch') const getTransactionTypes = async () => { const dirList = await Fetch('https://api.github.com/repos/ripple/xrpl-dev-portal/contents/content/references/protocol-reference/transactions/transaction-types').then(r => r.json()) const relevantFiles = dirList.filter(r => r.name.match(/^[a-zA-Z]+\.md$/)) return Promise.all(relevantFiles.map(async f => { const source = await Fetch(f.download_url).then(r => r.text()) return { transactionType: source.match(/^# ([a-zA-Z]+)/gm)[0].slice(2), docLink: 'https://xrpl.org/' + f.name.split('.')[0] + '.html', codeSamples: source.split(`\n`).join(' ').match(/```.+?```/gm) .map(s => s.split('```')[1].trim().replace(/^json[\n]*/gm, '')) .map(s => s.replace(/,[ \t\n\\t\\n]*}$/, '}')) .map(s => { try { return JSON.parse(s) } catch (e) { return s } }) } })) } const transactionTypes = await getTransactionTypes() console.log(transactionTypes)
  • XRPL nodes to hostname - /wietsewind/xrpl-nodes-to-hostname
    Last edited 3 months ago
    const fetch = require('node-fetch') const nodeToDomain = async () => { const manifests = (await (await fetch('https://validations.zaphod.ee/manifests.json')).json()) .map(r => r.result.details) .filter(r => r.domain !== '') .reduce((a, b) => Object.assign(a, { [b.master_key]: b.domain }), {}) const unlmap = await (await fetch('https://validations.zaphod.ee/unlmap.json')).json() const list = { ...manifests, ...unlmap } console.log(list) return list } console.log(nodeToDomain())
  • Get MultiSigned pubkey - /wietsewind/get-multisigned-pubkey
    Last edited 4 months ago
    const bc = require('ripple-binary-codec') const ms = '1200002400000003201B00503A406140000000000000016840000000000000677300811461D46A8DE4DAE4F72196C87995D9390BA82BA9F18314F84E8A80D08854F3621F9214D58F04D41A07EE10F3E01073210217241703CBC4D52C04D59269DE634B388E57C1E72F9462EEF4B435E041ED88367446304402204789F8AA9625D65FD65F43A7AC9FBFAEF64026A4BD1421B0F87ADE24B15F477302207241FDC7B31E15FDB121CA64623B6AC84475A30992E092F56656A731743B9FF781146B07151AAEC3405E3D83CEE654456B621EBF0007E1F1F9EA7C08536F6D65547970657D08536F6D6544617461E1EA7C09446576656C6F7065727D0B4057696574736557696E64E1F1' console.log( bc.decode(ms) .Signers .map(s => s.Signer.SigningPubKey) )
  • Secret Numbers Rollover - /wietsewind/secret-numbers-rollover
    Last edited 5 months ago
    const {Account, Utils} = require('xrpl-secret-numbers') const tests = { 'uInt16': 34462, 'Rollover (uInt16)': 34462 + parseInt('10000', 16) } Object.keys(tests).map(k => { const secretNumbers = Array(8).fill(tests[k]).map((_, i) => { return String(_) + Utils.calculateChecksum(i, _) }) const familySeed = new Account(secretNumbers).getFamilySeed() console.log(`${k}: ${familySeed}`, secretNumbers.join(' ')) })
  • Recover 1char Ripple Secret - /wietsewind/recover-1char-ripple-secret
    Last edited 6 months ago
    const kp = require('ripple-keypairs') // The secret below is a secret with one char missing. let secret = 'shx31Co5jta7Jp2ky1govCC8DSRb' let len = secret.length + 1 let alph = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890' let alphlen = alph.length for(let i = 1; i < len; i++) { for(let l = 0; l < alphlen; l++){ let gensecret = secret.substring(0, i) + alph.substring(l, l + 1) + secret.substring(i) try { let pair = kp.deriveKeypair(gensecret) let wallet = kp.deriveAddress(pair.publicKey) console.log('Secret', gensecret) console.log('Address', wallet) process.exit(0) } catch (e) { } } } return
  • Fetch XRPUSD price from the XRPL using JSON RPC - /wietsewind/fetch-xrpusd-price-from-the-xrpl-using-json-rpc
    Last edited 6 months ago
    const fetch = require('node-fetch') const account = 'rXUMMaPpZqPutoRszR29jtC8amWq3APkx' ;(async () => { const call = await fetch('https://xrpl.ws', { method: 'POST', body: JSON.stringify({ method: 'account_lines', params: [ { account } ] }) }) const lines = (await call.json()).result.lines console.log('XRPUSD = ' + lines.filter(l => l.currency === 'USD')[0].limit) })()
  • Fetch XRPUSD price from the XRPL using WebSockets - /wietsewind/fetch-xrpusd-price-from-the-xrpl-using-websockets
    Last edited 6 months ago
    const WebSocket = require('ws') const account = 'rXUMMaPpZqPutoRszR29jtC8amWq3APkx' const ws = new WebSocket('wss://xrpl.ws') ws.on('open', () => { ws.send(JSON.stringify({ command: 'account_lines', account })) }) ws.on('message', data => { const lines = JSON.parse(data).result.lines console.log('XRPUSD = ' + lines.filter(l => l.currency === 'USD')[0].limit) ws.close() }) 'Getting XRPL Price Info...'
  • MomentJS XUMM objects - /wietsewind/momentjs-xumm-objects
    Last edited 7 months ago
    const fetch = require('node-fetch') const moment = require('moment/min/moment-with-locales') exports.endpoint = async (req, res) => { const momentLocalesCall = await fetch('https://api.github.com/repositories/1424470/contents/src/locale') const momentLocalesJson = await momentLocalesCall.json() const momentLocalesData = momentLocalesJson.map(l => l.name.split('.')[0]) const xummLocalesCall = await fetch('https://translate.xumm.dev/json/export-meta') const xummLocalesJson = await xummLocalesCall.json() if (res !== null) { res.setHeader('Content-Type', 'application/json; Charset=UTF-8') res.setHeader('Access-Control-Allow-Origin', '*') res.setHeader('Access-Control-Allow-Methods', '*') } const xummLocaleToMomentJsLocale = Object.keys(xummLocalesJson.languages) .reduce((a, b) => { let resolvedLocale = 'en' if (momentLocalesData.indexOf(b.toLowerCase()) > -1) { resolvedLocale = b.toLowerCase() } else if (momentLocalesData.indexOf(b.split('-')[0].toLowerCase()) > -1) { resolvedLocale = b.split('-')[0].toLowerCase() } else { // Check alias const aliasses = Object.keys(xummLocalesJson['language-code-alias']).filter(k => { return xummLocalesJson['language-code-alias'][k].toLowerCase() === b.toLowerCase() }) if (aliasses.length > 0) { aliasses.forEach(a => { const alias = a.toLowerCase().replace('_', '-') if (momentLocalesData.indexOf(alias) > -1) { resolvedLocale = alias } }) } } moment.locale(resolvedLocale) const localeData = moment.localeData() Object.assign(a, { [b]: { momentJsCode: resolvedLocale, momentJsSource: Object.keys(localeData).reduce((c, d) => { if ( ['RegExp', 'Function'].indexOf(localeData[d].constructor.name) < 0 && !d.match(/(Parse|Regex)$/) && d !== '_config' ) { Object.assign(c, { [d.replace(/^_/, '')]: localeData[d] }) } return c }, {}) } }) return a }, {}) if (res !== null) { return res.end(JSON.stringify(xummLocaleToMomentJsLocale)) } else { // return console.log(xummLocaleToMomentJsLocale.nl.momentJsSource) return console.log(xummLocaleToMomentJsLocale) } } exports.endpoint(null, null)
  • Monitor XRPL Testnet Servers - /wietsewind/monitor-xrpl-testnet-servers
    Last edited 7 months ago
    const WebSocket = require('websocket').client const ServersToTest = [ 'testnet.xrpl-labs.com', 's.altnet.rippletest.net:51233' ] exports.endpoint = (request, response) => { Promise.all(ServersToTest.map(Server => { return new Promise((resolve, reject) => { let WsInstance = new WebSocket() WsInstance.connect('wss://' + Server) WsInstance.on('connectFailed', error => { console.log('Connect Error ' + Server, error.toString()) resolve({ server: Server, status: 'ConnectError', data: null, errorData: error.toString() }) }) WsInstance.on('connect', c => { // console.log('Connected ' + Server, c) c.on('message', m => { let data = JSON.parse(m.utf8Data) // console.log('Message ' + Server, data) resolve({ server: Server, status: 'Response', data: data, errorData: null }) c.close() }) c.on('close', () => { // console.log('Closed ' + Server) }) c.on('error', e => { console.log('Error ' + Server, e.toString()) resolve({ server: Server, status: 'MsgError', data: null, errorData: e.toString() }) }) c.send(JSON.stringify({ command: 'server_info' })) setTimeout(() => { c.close() resolve({ server: Server, status: 'Timeout', data: null, errorData: null }) }, 5000) }) }) })).then(Results => { // Running in the browser, respond let highestLedger = Math.max.apply(Math, Results.filter(r => { return r.status === 'Response' && r.data !== null && r.data.result.info.complete_ledgers.match(/[0-9]/) }).map(r => { return parseInt(r.data.result.info.complete_ledgers.split(',').reverse()[0].split('-').reverse()[0]) }).filter(r => { return !isNaN(r) })) let OutputData = { highestLedger: highestLedger, responses: Object.assign({}, ...Results.map(r => { let lastLedger = 0 if (r.data !== null) { lastLedger = parseInt(r.data.result.info.complete_ledgers.split(',').reverse()[0].split('-').reverse()[0]) if (isNaN(lastLedger)) lastLedger = 0 } return { [r.server.replace(/[^a-z0-9]/g, '')]: Object.assign(r, { lastLedger: lastLedger, ledgerOffset: highestLedger - lastLedger }) } })) } if (response !== null) { response.end(JSON.stringify(OutputData)) } else { // Running in the console. Log. console.log('Done', OutputData) } }).catch(Error => { }) } // When in the browser... exports.endpoint(null, null)