Othent's Node.js/Express.js server to manage Arweave wallets/keys stored in Google Key Management Service, secured by Auth0.
Try our demo at kms-demo.othent.io!
Learn how to set it up at https://docs.othent.io or looking at our demo's code at https://github.com/Othent/KMS-test-repo.
First, you need to update .env
with a valid auth0CustomDomain
, auth0ClientDomain
, auth0ClientId
and auth0ClientSecret
values pointing to an Auth0
application created with the following params:
- Type:
Machine to Machine
. - Permissions / Scopes:
read:client_credentials
andupdate:users
(this cannot be change after creating the Application). - Credentials:
Client Secret (Post)
. - Grant Types:
Client Credentials
.
Also, the tenant both this Machine to Machine application and the Single Page application used the KMS SDK (KeyManagementService
) you are using should have
at least the actions/add-user-metadata.ts
action configured in its Login flow.
Then, simply run:
pnpm install
pnpm start
You don't need to configure the remaining 3 services:
- Google KMS will be replaced by a local mocked implementation (which uses the same keys for all users).
- MongoDB database won't be used (this logic is skipped).
- Slack integration won't be used (this logic is skipped).
You might also want to install VSCode's CodeQL extension. See https://codeql.github.com/.
Remember you need to set the different variables in .env
or your Cloud provider's secrets to enable the following services:
- Auth0's Machine to Machine and Single Page Applications applications, with the right actions configured in their tenant's Login flow
- Google KMS.
- MongoDB database.
- Slack integration.
As there's only one production / live version of the server project at a time, tests need to make sure that the current
server can take request and send responses that work with both the latest SDK (@othent/kms
) version, as well as older
versions.
Below we can see a breakdown of the main server functions and the data types the different SDK versions would send to them and expect as response.
This repository contains a specific .spec.ts
for each of these functions, to verify they work as expected and are
backwards-compatible. Alternatively, the playground project can be run
locally with an older (v1
) @othent/kms
by using an adapter (included in the repo, but commented out). However, keep
in mind that won't be as exhaustive as the test in this repo, and not all cases mentioned below will be tested.
-
createUser
-
The old server expects no data in
createUser
. -
The old server replies with
true
if the user was successfully created.
-
-
encrypt
-
The old SDK (according to the docs) takes
Uint8Array | string
, but in practice the old server only acceptsLegacyBufferObject | string
, as theUint8Array
would be serialized usingJSON.stringify()
and deserialized usingBuffer.from()
, which would not accept the resultingLegacyBufferRecord
.See:
-
The old server would reply with a
LegacyBufferObject
and the old SDK would return that as-is.See https://github.com/Othent/KeyManagementService/pull/18/files#r1686770313
-
-
decrypt
-
The old SDK (according to the examples) takes
LegacyBufferObject
(as returned fromencrypt
), but as the old server deserializes that usingBuffer.form()
, astring
would also be valid if encoded properly.See:
-
The old server would reply with a plain
string
.See https://github.com/Othent/KMS-server-new/pull/10/files#r1745868667
-
-
sign
-
The old SKD would only accept binary data that, after being serialized with
JSON.stringify()
would result in aLegacyBufferRecord
, which would then be deserialized by the old server withnew Uint8Array(Object.values(data))
See #10 (comment)
-
The old server would reply with a
LegacyBufferObject
and the old SDK would return that as-is.See https://github.com/Othent/KeyManagementService/pull/18/files#r1686770313
-
Version 2.0.0
of @othent/kms
improves and normalizes the data types accepted and returned by the different
functions, but doesn't change the shape in which that data is sent to the server, so that's still LegacyBufferRecord
for sign()
and LegacyBufferObject
for the other functions. That means that this new version of the SDK works with
the old backend.
The only breaking change is that decrypt
would not accept BufferObject
/ LegacyBufferObject
automatically, and
developers upgrading to 2.0.0
would have to convert those manually.
See: https://github.com/Othent/KeyManagementService/pull/18/files#r1686770313
Version 2.1.0
of @othent/kms
changes the shape in which that data is sent to the server, getting rid of the legacy
data types. That means that this new version of the SDK doesn't work with the old backend. These are the main changes:
-
Remove
data.keyName
and adddata.path
instead. -
Stop using
BufferObject
/LegacyBufferObject
/LegacyBufferRecord
and instead serialize/send all data asB64string
. -
The
data.data
construct when extracting the data from the server responses has been replaced to have specific property names for each endpoint (e.g.data.encryptedData
).
According to 3 sections above, the server needs to handle both the old format / data types (keyName
+ BufferObject
/ LegacyBufferObject
data) as well as the new ones (path
+ B64string
), so:
-
If
data.keyName
is present, validate the data according to the format / shape required by the old server (BufferObject
/LegacyBufferObject
/LegacyBufferRecord
). The exception to this iscreateUser
, which would not have anydata
. -
If
data.path
is present, validate the data according to the format / shape required by the new server (B64string
), and use a specific property name for each endpoint to return the response's data (e.g.data.encryptedData
).
-
Use
pnpm version
to bump the version, which will also make sure the next commit has the right tags.npm version patch npm version minor npm version major
The
preversion
,version
andpostversion
scripts defined inpackage.json
will test, format, build, tag and push all the changes automatically. See https://docs.npmjs.com/cli/v10/commands/npm-version. -
As soon as the new branch gets merged, a new up-to-date server will be deployed. You can verify the current live version with a
GET
request to https://kms-server.othent.io:{ "version": "2.0.0", "hasToken": false, "hasTokenData": false, "isTokenValid": false, "isTokenUnused": true }
If you added / pushed an incorrect tag, you can delete it from the server with:
git push origin :refs/tags/v0.1.0
And locally with:
git tag -d v0.1.0