wietsewind's notebooks

  • Get MultiSigned pubkey - /wietsewind/get-multisigned-pubkey
    Last edited 20 days 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 a month 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 2 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 3 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 3 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 3 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 3 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)
  • XRPL Buffer to Seed to Account - /wietsewind/xrpl-buffer-to-seed-to-account
    Last edited 4 months ago
    const kp = require('ripple-keypairs') const hex = '0123456789ABCDEF0123456789ABCDEF' // const entropy = Buffer.from(hex, 'hex') // console.log(entropy) // const secret = kp.generateSeed({entropy}) // const secret = kp.generateSeed({algorithm:'ed25519'}) // const pair = kp.deriveKeypair(secret) // const wallet = kp.deriveAddress(pair.publicKey) const wallet = kp.deriveAddress('ED' + 'A6CADFC1BF20EC6FC356FED95822A90C93D6ED410E2EB9F1F7DFFB8D066986F5') // console.log('Pair', pair) // console.log('Secret', secret) console.log('Address', wallet)
  • Simple XRPL Sha512-half keypair - /wietsewind/simple-xrpl-keypair
    Last edited 5 months ago
    const crypto = require('crypto') const rippleSecretCodec = require('ripple-secret-codec') const rippleKeypairs = require('ripple-keypairs') const passphrase = 'masterpassphrase' const hexSeed = crypto.createHash('sha512').update(passphrase).digest('hex').toUpperCase().substring(0, 32) console.log('hexSeed: ' + hexSeed) const secret = rippleSecretCodec.encodeHex(hexSeed).secret_b58 console.log('Secret: ' + secret) const keypair = rippleKeypairs.deriveKeypair(secret) const address = rippleKeypairs.deriveAddress(keypair.publicKey) const wallet = { address: address, secret: secret }
  • Parse UNL - /wietsewind/parse-unl
    Last edited 6 months ago
    const fetch = require('node-fetch') const {decode} = require('ripple-binary-codec') const {encodeNodePublic} = require('ripple-address-codec') const base64ToDecoded = base64 => decode(Buffer.from(base64, 'base64').toString('hex')) const pubkeyToNode = pubhex => encodeNodePublic(Buffer.from(pubhex, 'hex')) const main = async () => { const f = await fetch('http://vl.ripple.com/') const {manifest, blob} = await f.json() const {validators} = JSON.parse(Buffer.from(blob, 'base64').toString('utf-8')) return validators.map(v => { const manifest = base64ToDecoded(v.manifest) return { validation_public_key: v.validation_public_key, decodedManifestPubKeys: { PublicKey: pubkeyToNode(manifest.PublicKey), SigningPubKey: pubkeyToNode(manifest.SigningPubKey) }, manifest } }) } console.log(await main())