wietsewind's notebooks

  • Mnemonic with ripple-keypairs, w/o ripplelib - /wietsewind/mnemonic-with-ripple-keypairs-w-o-ripplelib
    Last edited a day ago
    const bip39 = require("bip39"); const bip32 = require("ripple-bip32"); const ripple = require('ripple-keypairs') var mnemonic = 'novel matter final only nice cheese address cradle civil crash great flame struggle consider crowd surface purpose saddle mango endless mixed trial tape wrap' // Or generate: // mnemonic = bip39.generateMnemonic() console.log('mnemonic: ' + mnemonic) const seed = bip39.mnemonicToSeed(mnemonic) // add second argument for 25th word encrypted // console.log('seed: ', seed) const m = bip32.fromSeedBuffer(seed) // console.log('m: ', m) const keyPair = m.derivePath("m/44'/144'/0'/0/0").keyPair.getKeyPairs() const address = ripple.deriveAddress(keyPair.publicKey) console.log('privateKey: ' + keyPair.privateKey) console.log('publicKey: ' + keyPair.publicKey) console.log('address: ' + address)
  • HEX Private key to address with ripple-lib - /wietsewind/hex-private-key-to-address-with-ripple-lib
    Last edited a day ago
    const keypairs = require('ripple-keypairs') const elliptic = require('elliptic') const secp256k1 = elliptic.ec('secp256k1') const ed25519 = elliptic.eddsa('ed25519') function bytesToHex(a) { return a.map(function(byteValue) { const hex = byteValue.toString(16).toUpperCase() return hex.length > 1 ? hex : '0' + hex }).join('') } /* secp256k1 */ let secp256k1_privateKey = '00' + '0762EED5BA4F378FFA60621C6DEF72F4A0A579112ADA5F5D6B2A35EC27E893A5' let secp256k1_keypair = { privateKey: secp256k1_privateKey, publicKey: bytesToHex(secp256k1.keyFromPrivate(secp256k1_privateKey.slice(2)).getPublic().encodeCompressed()), } console.log('secp256k1 Keypair, Address ', secp256k1_keypair, keypairs.deriveAddress(secp256k1_keypair.publicKey)) /* ed25519 */ let ed25519_privateKey = 'ED' + '3AD7B2EC2CFD134C500867164E4E257FD703C2CF4915E93A8CFC0CC7C2DBA46B' let ed25519_keypair = { privateKey: ed25519_privateKey, publicKey: 'ED' + bytesToHex(ed25519.keyFromSecret(ed25519_privateKey.slice(2)).pubBytes()), } console.log('ed25519 Keypair, Address ', ed25519_keypair, keypairs.deriveAddress(ed25519_keypair.publicKey))
  • Get GH XRPL Tx Types - /wietsewind/get-gh-xrpl-tx-types
    Last edited 8 days 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/rippled-api/transaction-formats/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)
  • Finishable XRPL Escrows - /wietsewind/finishable-xrpl-escrows
    Last edited 22 days ago
    const Fetch = require('node-fetch') const Client = require('rippled-ws-client') const Sign = require('rippled-ws-client-sign') const Seed = process.argv[2] || '' new Client('wss://xrpl.ws').then(Connection => { Fetch('https://ledger.exposed/api/escrowlist').then(r => r.json()).then(Escrows => { const ToFinish = Escrows.filter(Escrow => { return Escrow.FinishAfter <= Math.round((new Date()) / 1000) - 946684800 && Escrow.Condition === undefined }).slice(0, 1) ToFinish.forEach(Escrow => { Connection.send({ command: 'account_objects', account: Escrow.Account, limit: 400 }).then(AccountObjects => { const Escrows = AccountObjects.account_objects.filter(Obj => Obj.LedgerEntryType === 'Escrow') Escrows.forEach(Escrow => { Connection.send({ command: 'tx', transaction: Escrow.PreviousTxnID }).then(CreateTx => { const FinishJson = { Account: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', TransactionType: 'EscrowFinish', Owner: Escrow.Account, OfferSequence: CreateTx.Sequence } new Sign(FinishJson, Seed, Connection) .then(TransactionSuccess => { console.log('TransactionSuccess', TransactionSuccess) }).catch(SignError => { console.log('SignError', SignError.details) }) }) }) }) }) }) })
  • XRPL Buffer to Seed to Account - /wietsewind/xrpl-buffer-to-seed-to-account
    Last edited 24 days ago
    const kp = require('ripple-keypairs') const hex = '0123456789ABCDEF0123456789ABCDEF' const entropy = Buffer.from(hex, 'hex') console.log(entropy) const secret = kp.generateSeed({entropy}) const pair = kp.deriveKeypair(secret) const wallet = kp.deriveAddress(pair.publicKey) console.log('Secret', secret) console.log('Address', wallet)
  • Sign XRP TX using HEX privateKey - /wietsewind/sign-xrp-tx-using-hex-privatekey
    Last edited a month ago
    const ripple = require('ripplelib') const sign = require('ripple-sign-keypairs') // NOTE! ripplelib isn't working in Safari 10.1 (wrong public key generated from private key) - use // ripple-keypairs, as displayed in: // > https://runkit.com/wietsewind/hex-private-key-to-address-with-ripple-lib // > https://runkit.com/wietsewind/mnemonic-with-ripple-keypairs-w-o-ripplelib var privateKey = '0762EED5BA4F378FFA60621C6DEF72F4A0A579112ADA5F5D6B2A35EC27E893A5' const key = ripple.KeyPair.from_json(privateKey) const keyPair = { privateKey: '00' + key.to_hex_pri(), publicKey: key.to_hex_pub() } console.log('privateKey: ' + keyPair.privateKey) console.log('privateKeyWif: ' + key.to_pri_string()) // to_wif console.log('publicKey: ' + keyPair.publicKey) console.log('address: ' + key.to_address_string()) // // Now sign a transaction... // var tx = { // TransactionType: 'Payment', // Account: key.to_address_string(), // Fee : (0.000012 * 1000 * 1000) + '', // Destination: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', // DestinationTag : 2, // Amount: (1 * 1000 * 1000) + '', // Sequence: 0 // } // var txJSON = JSON.stringify(tx) // var txSign = sign(txJSON, keyPair) // console.log(txSign) // return txSign
  • Reserved - /wietsewind/reserved
    Last edited a month ago
    const Client = require('rippled-ws-client') const account = 'rPyFs5kpbiiawSdP9JGdaYM33zfUUah1TY' // const account = 'rPdvC6ccq8hCdPKSPJkPmyZ4Mi1oG2FFkT' const c = new Client('wss://xrpl.link').then(Connection => { Connection.send({ command: 'account_tx', account: account }).then(txs => { console.log('Got', txs.transactions.length) if (typeof txs.transactions !== 'undefined' && txs.transactions && txs.transactions.length > 0) { const incomingTxs = txs.transactions.filter(tx => { return tx.tx.Destination === account }) const incomingTxCountWithTag = incomingTxs.filter(tx => { return typeof tx.tx.TransactionType === 'string' && typeof tx.tx.DestinationTag !== 'undefined' }).length const senders = txs.transactions.map(tx => { return tx.tx.Account || '' }) const uniqueSenders = senders.filter((elem, pos) => { return senders.indexOf(elem) === pos }).length const percentageTag = Math.round(incomingTxCountWithTag / incomingTxs.length * 100) console.log('Unique senders: ' + uniqueSenders) console.log('With tag: ' + incomingTxCountWithTag) console.log('Percentage: ' + percentageTag) if (uniqueSenders >= 10 && percentageTag > 50) { console.log('This is most likely an exchange or custodian, tag required') } else { console.log('Tag is probably not required...') } } Connection.close() }).catch(e => console.log(e.message)) })
  • Get XRPL Exchanged Value - /wietsewind/get-xrpl-exchanged-value
    Last edited 2 months ago
    const Client = require('rippled-ws-client') const TxParser = require('ripple-lib-transactionparser') const main = async () => { console.log('Connecting') const connection = await new Client('wss://xrpl.ws') console.log('Connected, requesting transaction') const transaction = await connection.send({ command: 'tx', transaction: '63488A0526DC0196AB89DD7DAE2A972A2E75808086287C02587603E8C46B6532' }) console.log('Tx by Account', transaction.Account) console.log(TxParser.parseBalanceChanges(transaction.meta)[transaction.Account]) return connection.close() } main()
  • Verify XRPL Signature (XUMM) - /wietsewind/verify-xrpl-signature-xumm
    Last edited 2 months ago
    const verifySignature = require('verify-xrpl-signature').verifySignature const someTx = '228000000024000000D568400000000000000C732102C71103C10E706EFCBACDBC1A1F505D0421369CD625A9953990393E14202DC15274463044022035B6ABAC593979FBB745E8DB71B2CCDC255220EFE03ECC9037F7E0DA6356F0A302201119ED7F26D4131A2E24607B60911ED7E01571FD82F433640562C755135D397981146C09EF73F2C503101303D9716D3209A90732ACBD' // { // "Flags": 2147483648, // "Sequence": 213, // "Fee": "12", // "SigningPubKey": "02C71103C10E706EFCBACDBC1A1F505D0421369CD625A9953990393E14202DC152", // "TxnSignature": "3044022035B6ABAC593979FBB745E8DB71B2CCDC255220EFE03ECC9037F7E0DA6356F0A302201119ED7F26D4131A2E24607B60911ED7E01571FD82F433640562C755135D3979", // "Account": "rwiEtsEY8YRxgHQgvWXsxyUBSZzTMqL2EX" // } console.log(verifySignature(someTx)) // In case of explicit MultiSign signer verification: // console.log(verifySignature(someTx, 'rwiETSee2wMz3SBnAG8hkMsCgvGy9LWbZ1'))
  • Ripple Wallet Generator (raw) - /wietsewind/ripple-wallet-generator-raw
    Last edited 3 months ago
    const crypto = require('crypto') const rippleSecretCodec = require('ripple-secret-codec') const rippleKeypairs = require('ripple-keypairs') const ripple = require('ripple-lib').RippleAPI const rippleApi = new ripple() var passphrase = 'masterpassphrase' // Create a SHA512 hash from the `passphrase` var hash = crypto.createHash('sha512').update(passphrase).digest('hex').toUpperCase() // Get the first 32 chars var hexSeed = hash.substring(0,32) // Encode in base58 with Ripple-aphabet. Here's our secret console.log('hexSeed: ' + hexSeed) var secret = rippleSecretCodec.encodeHex(hexSeed).secret_b58 console.log('Secret: ' + secret) // Generate keypair with secret var keypair = rippleKeypairs.deriveKeypair(secret) // Retrieve the wallet address var address = rippleKeypairs.deriveAddress(keypair.publicKey) // Create object with secret & wallet address var wallet = { address: address, secret: secret } console.log('Passphrase: ' + passphrase) console.log('Address: ' + address) // Now sign a transaction... var tx = { TransactionType: 'Payment', Account: address, Fee : (0.000012 * 1000 * 1000) + '', Destination: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', DestinationTag : 2, Amount: (1 * 1000 * 1000) + '', Sequence: 0 } var txJSON = JSON.stringify(tx) var txSign = rippleApi.sign(txJSON, secret) return txSign