feat: 🎉 Created basic functionality

main
Keith Irwin 2024-04-20 14:25:00 -06:00
parent 4765af941f
commit 91b1646f6e
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
4 changed files with 184 additions and 3 deletions

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# monero-wallet-rpc-js
Simple wrapper for monero-wallet-rpc calls.
```javascript
import Wallet from 'monero-wallet-rpc-js'
// Create a new walletRpc connection
const wallet = new Wallet({
url: 'http://localhost:18082',
filename: 'mywallet',
password: 'secretpassword',
address: '4....',
viewKey: 'XXXXXXX....',
restoreHeight: '573936',
})
// Call it
let height = await wallet.rpc('get_height')
console.log(`Synced height: ${height}`)
```

55
main.js
View File

@ -1,3 +1,54 @@
exports.walletRpc = (method, params) => {
console.log(`walletRpc(${method}) called`)
import axios from 'axios'
exports.Wallet = class Wallet {
url; wallet; password;
address; viewKey; restoreHeight;
constructor (settings) {
this.url = `${settings.url}/json_rpc`
this.wallet = settings.filename
this.password = settings.password
this.address = settings.address
this.viewKey = settings.viewKey
this.spendKey = settings.spendKey
this.restoreHeight = settings.restoreHeight
// Open wallet
try {
this.rpc('open_wallet', {
filename: this.wallet,
password: this.password,
})
console.log(`Opened wallet "${this.wallet}".`)
} catch (openErr) {
console.log(`Failed to open wallet "${this.wallet}".`)
// create wallet
try {
this.rpc('generate_from_keys', {
restore_height: this.restoreHeight,
filename: this.wallet,
address: this.address,
spendKey: this.spendKey,
viewKey: this.viewKey,
password: this.password
})
console.log(`Created wallet "${this.wallet}".`)
} catch (createErr) {
console.error(`Failed to open wallet "${this.wallet}": ${openErr}`)
console.error(`Failed to create wallet "${this.wallet}": ${createErr}`)
}
}
}
async rpc (method, params) {
return await axios.post(this.url, {
jsonrpc: '2.0',
id: '0',
method: method,
params: params,
})
}
}

106
package-lock.json generated Normal file
View File

@ -0,0 +1,106 @@
{
"name": "monero-wallet-rpc-js",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "monero-wallet-rpc-js",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"axios": "^1.6.8"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.6.8",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/follow-redirects": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
}
}
}

View File

@ -11,5 +11,8 @@
"url": "https://gitea.gf4.pw/ki9/monero-wallet-rpc-js"
},
"author": "Keith Irwin (www.ki9.us)",
"license": "MIT"
"license": "MIT",
"dependencies": {
"axios": "^1.6.8"
}
}