drp-libsodium-test/README.md

43 lines
2.5 KiB
Markdown

This is example code for using [libsodium.js](https://github.com/jedisct1/libsodium.js/tree/0.7.11) installed via `NPM` to cross-test OSIRAA "setup pairwise key" calls.
- Run OSIRAA 0.7.1
- Set up OSIRAA to talk to a covered business with `Api root endpoint` set to http://127.0.0.1:9000 .
- Navigate to http://localhost:8000/data_rights_request/ & select the CB you just created
- Run this script, specifying the verify key from OSIRAA's `keys.json`, it will listen on port 9000.
- Press the Setup Pair-wise Key button
- should see response code 200 & response payload containing token "fake-token-do-not-use" if the message was signed successfully.
When run with a valid key, it will print the message and return status code 200, when run with an invalid key it will return 500 and emit a stack trace:
```
[nix-shell:~/Code/libsodium-mvp]$ node index.js b0409a509cf611a0529ff25df555f692e896eaeb599bfc6e402fa18e523ad7a0
waiting for nacl...
b0409a509cf611a0529ff25df555f692e896eaeb599bfc6e402fa18e523ad7a0
starting express server...
listening on http://127.0.0.1:9000/
{
'agent-id': 'OSIRAA_LOCAL_001',
'business-id': 'LIBSODIUM_TESTER_DO_NOT_USE',
'expires-at': '2023-04-25T18:06:39.541684+00:00',
'issued-at': '2023-04-25T17:51:39.541684+00:00'
}
C-c C-c
[nix-shell:~/Code/libsodium-mvp]$ node index.js b0409a509cf611a0529ff25df555f692e896eaeb599bfc6e402fa18e523ad7a1
waiting for nacl...
b0409a509cf611a0529ff25df555f692e896eaeb599bfc6e402fa18e523ad7a1
starting express server...
listening on http://127.0.0.1:9000/
Error: incorrect signature for the given public key
at b (/home/rrix/Code/libsodium-mvp/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js:1:17811)
at Object.et [as crypto_sign_open] (/home/rrix/Code/libsodium-mvp/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js:1:73541)
at file:///home/rrix/Code/libsodium-mvp/index.js:41:43
at Layer.handle [as handle_request] (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/layer.js:95:5)
at next (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/layer.js:95:5)
at /home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/index.js:284:15
at param (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/index.js:365:14)
at param (/home/rrix/Code/libsodium-mvp/node_modules/express/lib/router/index.js:376:14)
```