brave-intl / bat-client Goto Github PK
View Code? Open in Web Editor NEWAn example of client code for the BAT.
License: Mozilla Public License 2.0
An example of client code for the BAT.
License: Mozilla Public License 2.0
The root cause appears to be fixed in bitgojs
BitGo/BitGoJS@6b2296f
we should update when a new release is available
requires brave-intl/bat-ledger#240 to be merged into master for staging & production; until then, run the https://github.com/brave-intl/bat-ledger/tree/support-batched-votes branch locally
Currently storage and (de)serialization of bat-client state, is handled by browser-laptop. Unfortunately this means we are exposing some internal concerns to browser-laptop.
One such concern is that the cryptographic seed is internally stored as a Uint8Array. Standard JSON serialization via JSON.stringify
/JSON.parse
is not invertible on Uint8Array objects. Since browser-laptop uses JSON.stringify
for storing the seed, it needs to perform conditional fixup to ensure that it passes a Uint8Array to bat-client on init. https://github.com/brave/browser-laptop/blob/f6992aadba9c681302fe1cec3d0e28e222b3f62c/app/browser/api/ledger.js#L1590
That fixup is not currently being performed during restore of newClient
which is used for continuing transition from BTC->BAT, causing brave/browser-laptop#11673
npm run test
shows a security error:
> nsp check
(+) 1 vulnerabilities found
┌───────────────┬─────────────────────────────────────────────────────────────┐
│ │ Large gzip Denial of Service │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Name │ superagent │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ CVSS │ 3.7 (Low) │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Installed │ 3.5.2 │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Vulnerable │ <3.7.0 │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Patched │ >=3.7.0 │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Path │ [email protected] > [email protected] > [email protected] │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ More Info │ https://nodesecurity.io/advisories/479 │
└───────────────┴─────────────────────────────────────────────────────────────┘
currently the bat-client blindly signs the transaction that is returned from the ledger server. better to be defensive and check that the amount matches expectations (<= self.state.properties.fee.amount
)
found by @evq
Right now it is 64 bytes. It could safely be reduced to 32 bytes if you save only the seed which is used to derive the signing keypair. See https://github.com/brave/sync/blob/staging/lib/crypto.js#L119-L121 for an example.
IMO this is a worthwhile change to make for usability's sake. Users would only have to write down 16 words to backup/recover the keypair instead of 32 words.
there's some methods duplicated among the bat-* repos (retryTrip
for instance). these should be split into a shared library so that if there's a bug in one of these methods, it doesn't need to be fixed and reviewed multiple times.
Line 464 in 2ed3fc7
the correctness of this code depends on how Niceware does buffer allocation. for instance, this works the way we want it to:
var n = Buffer.alloc(4)
new Uint8Array(Buffer.from(n.buffer, n.length / 2)) // returns Uint8Array [ 0, 0 ] as expected
however, this code gives completely different results:
n = new Buffer([0,0,0,0])
new Uint8Array(Buffer.from(n.buffer, n.length / 2)) // returns a 8190 length Uint8Array!
this is because the .buffer
property refers to the ArrayBuffer property referenced by the Buffer at construction time. In the latter case, .buffer
is the internal memory pool of the Buffer, which has default size 8192 bytes in node.
since Niceware's buffer allocation may change at any time, this code should not depend on it working the way it does right now.
BAT-Client is still trying to fetch rulesets from
/v1/publisher/ruleset?consequential=true
resulting in #goaway's
This file is used to generate reproducible builds and it is recommended to check it into git: https://docs.npmjs.com/files/package-lock.json
is there any reason it's gitignored in this repo?
we should add a failout path such that we always try using the current surveyor, this allows for non-backwards compatible upgrades to surveyors
LEDGER_VERBOSE=true
Actual result:
[ response for GET https://ledger.mercury.basicattentiontoken.org/v2/wallet/941ec251-3187-41fc-b10b-13bd62f6e2df?balance=true&refresh=true&amount=25&altcurrency=BAT ]
>>> HTTP/1.1 503
>>> cache-control: no-cache, no-store
>>> connection: keep-alive
>>> content-length: 506
>>> content-type: text/html; charset=utf-8
>>> date: Wed, 11 Oct 2017 07:33:19 GMT
>>> server: Cowboy
>>>
>>> <!DOCTYPE html>
>>> <html>
>>> <head>
>>> <meta name="viewport" content="width=device-width, initial-scale=1">
>>> <meta charset="utf-8">
>>> <title>Application Error</title>
>>> <style media="screen">
>>> html,body,iframe {
>>> margin: 0;
>>> padding: 0;
>>> }
>>> html,body {
>>> height: 100%;
>>> overflow: hidden;
>>> }
>>> iframe {
>>> width: 100%;
>>> height: 100%;
>>> border: 0;
>>> }
>>> </style>
>>> </head>
>>> <body>
>>> <iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>
>>> </body>
>>> </html>
+++ busyP=true
<<< GET https://mercury-proxy.privateinternetaccess.com/v2/surveyor/voting/FSgBEh6UD%2Fw3Akir95Fz5h8n5Un6n%2FxudYsegnqkxAF/6a0af783a6240d18354e414b4e7beb9
<<< content-type: application/json; charset=utf-8
<<< accept-encoding:
<<<
Expected result:
Should handle the recovery scenario properly
Reproduces how often: [What percentage of the time does it reproduce?]
100%
about:brave info:
Brave | 0.19.39 |
---|---|
rev | ebcd280 |
Muon | 4.4.27 |
Reproducible on current live release:
N/A
cc : @evq @NejcZdovc @mrose17
this repo now has tests! it should run the tests and require passing tests for merge
https://user-images.githubusercontent.com/3362943/31228726-6e5e714c-aa19-11e7-9b95-7fde0ab40e59.png
There seems to be no need for the UUID (Key 1 in the screenshot above) because we can use the Key 2 public key fingerprint as a wallet identifier. This would greatly improve usability for key backup and recovery.
This was broken with this commit, where recovery logic was changed brave/ledger-client@d2eed50
currently there is a branch that fetches from the ledger server if payment is overdue. since this is a fairly common case (wallets with zero balance) the ledger server is getting hit much more than it should
same issue as brave-intl/bat-balance#1
requires brave-intl/bat-ledger#215 to be merged into master for staging & production; until then, run the https://github.com/brave-intl/bat-ledger/tree/add-more-alturrencies branch locally
sshpk < 1.14.1
https://nodesecurity.io/advisories/606
metascraper: no fix available
https://nodesecurity.io/advisories/603
cc @diracdeltas @NejcZdovc @evq
metascraper appears to be an older (probably indirect) bat-publisher
dependency
Per brave/browser-laptop#11495 (comment)
Ran into an issue while testing that PR... Here's what I did:
ledger-newstate.json
gets persisted before and after after sync 👍<<< POST https://ledger.mercury.basicattentiontoken.org/v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893
<<< content-type: application/json; charset=utf-8
<<< accept-encoding:
<<<
<<< {
<<< "requestType": "httpSignature",
<<< "request": {
<<< "headers": {
<<< "digest": "SHA-256=oe2fifEDcfI96boPcKaUUhe/HKWiuzyoBs10Gm+S4bg=",
<<< "signature": "keyId=\"primary\",algorithm=\"ed25519\",headers=\"digest\",signature=\"vglrshpOIBjtoW6OBmW70pH7/RFK7vwzY+a3a9rDdwGxIU9VTBgj0Snm2AEHrqQUuR3mA+EX817oh/z/607FCg==\""
<<< },
<<< "body": {
<<< "label": "4123099f-47e4-48ad-bc9f-6cdffebd81ed",
<<< "currency": "BAT",
<<< "publicKey": "429fb47298b7b058030c3d1bca1ca587585a81b1e47f0ecc9436e04306210043"
<<< },
<<< "octets": "{\"currency\":\"BAT\",\"label\":\"4123099f-47e4-48ad-bc9f-6cdffebd81ed\",\"publicKey\":\"429fb47298b7b058030c3d1bca1ca587585a81b1e47f0ecc9436e04306210043\"}"
<<< },
<<< "proof": "1ed2a2b0748089c8ccd81e7dac8c893\n7FxI5Yngr+RGK1uVGD9rWf/RMzpzMz2irqOoj6t9DOH 5xbHQ55+WSAbb5PjpJhKRGY/1u65rlE2BEXkt/HSBMe 1\n13D36D8a7pG56RdRGmI0NoNPY7AjP4YaYh+fTjIjFTv 8gwqQ7TkDtR9rJ6XNhQ6j5RpWY6CEbFKtCMPks4UmkM 1\n2YOcc2YrRugyGZOJrgDOGhBWwO/6+OsMCaJ0RbbjOx9\n5j3+EjAim1nxwiO7UbO8Gc17maim1QxYP5pMWTgUh2b 4WdiDvvTxgXwZc2xueVmFhnvAJ0CawmUaCDZ6Bsr5G5\n\n6PDzgyvawQBE+Ndu7yAV3XiGyV4gcnRKV74Q5QqQYvS 7i16apf3Fk4v3bdROu1fm9DEVrFRCFx0qhzY1woyJcB 1\nF5KSCVbKPt+9RXeAPt7WCaAwVjAeEf1UhxvsjhEYMTg\nBETV/Mnj5p0TjkQO6/MEbQrUPXdoRCXBfAH/fPDF+Ai 3UqevUsbtwxqNn9hVwaZeh13SlCYYDuaP9brmW9wz9n\n\n5wSFmTSkk3rgWr90uyHne1ZQ3c4xfsCuGMAPw0bHw56 4yIpZvGfdV+6pi0WMSZ55knoA1WJ0RK+dZdS2qXd01n 1\nEyxwGIpFJnew4/ltJlP9bmKSHIl/YOGai0VgBSxKVmm\n9cD1As+2yjj4+bgD56OlhDiRnihOvU4dgOtGskhfx8w 8RF3dVpPL0hSBfV1DM+VmDqNBBJw0qu0mDx2NvTFOcC\n\n3GdmB6jP/KLU/zk9ya2f0GO+O1rjkv/yiSKxDZm57XD 4P/fkCg3ka+pw0o+aByXOnx+CM9dkTNLi/nVVG6SHek 1\n3AmjLTzsgwrq7yy4VvobP6XC0YCINMGpdX+uEMEYcJ\nAjfAU8PaYhcZHNhBJtGUsnk1khsH1I9WS3mbYHmc3RK B1lMaDXW+LwBT7z4hK7QXarvMVO/7G4/uF482IAd0zA\n\n\n"
<<< }
[ response for POST https://ledger.mercury.basicattentiontoken.org/v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893 ]
>>> HTTP/1.1 422
>>> cache-control: no-cache
>>> connection: keep-alive
>>> content-length: 120
>>> content-type: application/json; charset=utf-8
>>> date: Fri, 13 Oct 2017 06:02:22 GMT
>>> server: Cowboy
>>> vary: accept-encoding
>>> via: 1.1 vegur
>>> x-rate-limit-limit: 60
>>> x-rate-limit-remaining: 59
>>> x-rate-limit-reset: 1507874601
>>>
>>> {"statusCode":422,"error":"Unprocessable Entity","message":"persona credential exists: 1ed2a2b0748089c8ccd81e7dac8c893"}
ledger client error(3): {}
Error: HTTP response 422 for POST /v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893
at request.request (/Users/clifton/Documents/browser-laptop/app/browser/api/ledger.js:1491:9)
at Function.defaultSession.webRequest.fetch (/Users/clifton/Documents/browser-laptop/js/lib/request.js:55:5)
if the PUT
call to /v2/wallet/{paymentId}
sees HTTP code 410 immediately prior to https://github.com/brave-intl/bat-client/blob/master/index.js#L936 this indicates that the earlier call at https://github.com/brave-intl/bat-client/blob/master/index.js#L936 to get the current surveyor information is no longer valid.
instead of invoking the callback with an error, the client should fetch the new current surveyor and try again. however, to avoid looping, it should do this at most once.
the fallback should be 'https://ledger-staging.mercury.basicattentiontoken.org' instead of 'ledger-staging.mercury.basicattentiontoken.org' in
Line 36 in 2ed3fc7
See brave/browser-laptop#6944 for context; random-lib<3.0.0 has bias in its random integer generation.
https://github.com/brave/crypto 0.1.0 now supports passphrase recovery
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.