Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit 14087fa

Browse files
author
Austin King
authored
feat: add ability to post identity key via admin API (#628)
* feat: add ability to post identity key via admin API * fix: lint * fix: use optional type instead of undefined and remove unnecessary uppercase function
1 parent 1ab6fd7 commit 14087fa

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/data-access/users.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export async function checkUserExistence(payId: string): Promise<boolean> {
3333
*
3434
* @param payId - The PayID to insert in the account table.
3535
* @param addresses - The payment addresses for that PayID to insert into the database.
36+
* @param identityKey - Base64 encoded public key of user for signing addresses.
3637
*
3738
* @returns The addresses inserted for this user.
3839
*/
@@ -41,11 +42,13 @@ export async function checkUserExistence(payId: string): Promise<boolean> {
4142
export async function insertUser(
4243
payId: string,
4344
addresses: readonly AddressInformation[],
45+
identityKey?: string,
4446
): Promise<readonly AddressInformation[]> {
4547
return knex.transaction(async (transaction: Transaction) => {
4648
const insertedAddresses = await knex
4749
.insert({
4850
payId,
51+
identityKey,
4952
})
5053
.into<Account>('account')
5154
.transacting(transaction)

src/middlewares/users.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function postUser(
9898
// TODO:(hbergren) Need to test here and in `putUser()` that `req.body.addresses` is well formed.
9999
// This includes making sure that everything that is not ACH or ILP is in a CryptoAddressDetails format.
100100
// And that we `toUpperCase()` paymentNetwork and environment as part of parsing the addresses.
101-
await insertUser(payId, req.body.addresses)
101+
await insertUser(payId, req.body.addresses, req.body.identityKey)
102102

103103
// Set HTTP status and save the PayID to generate the Location header in later middleware
104104
res.locals.status = HttpStatus.Created
@@ -125,6 +125,7 @@ export async function putUser(
125125
const rawPayId = req.params.payId
126126
const rawNewPayId = req.body?.payId
127127
const addresses = req.body?.addresses
128+
const identityKey = req.body?.identityKey
128129

129130
// TODO:(hbergren) More validation? Assert that the PayID is `$` and of a certain form?
130131
// Do that using a regex route param in Express?
@@ -171,7 +172,7 @@ export async function putUser(
171172

172173
updatedAddresses = await replaceUser(payId, newPayId, addresses)
173174
if (updatedAddresses === null) {
174-
updatedAddresses = await insertUser(newPayId, addresses)
175+
updatedAddresses = await insertUser(newPayId, addresses, identityKey)
175176
statusCode = HttpStatus.Created
176177
}
177178

test/integration/e2e/admin-api/postUsers.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ describe('E2E - adminApiRouter - POST /users', function (): void {
4848
.expect(HttpStatus.Created, done)
4949
})
5050

51+
it('Returns a 201 when creating a new user with an identity key', function (done): void {
52+
const payId = 'jacksmith$xpring.money'
53+
const identityKey = `Imp3ayI6IHsKICAia3R5IjogIkVDIiwgCiAgInVzZSI6ICJzaWciL`
54+
55+
// GIVEN a user with a PayID known to not exist on the PayID service
56+
const userInformation = {
57+
payId,
58+
identityKey,
59+
addresses: [
60+
{
61+
paymentNetwork: 'XRPL',
62+
environment: 'TESTNET',
63+
details: {
64+
address: 'TVQWr6BhgBLW2jbFyqqufgq8T9eN7KresB684ZSHKQ3oDth',
65+
},
66+
},
67+
],
68+
}
69+
70+
// WHEN we make a POST request to /users with that user information
71+
request(app.adminApiExpress)
72+
.post(`/users`)
73+
.set('PayID-API-Version', payIdApiVersion)
74+
.send(userInformation)
75+
.expect('Content-Type', /text\/plain/u)
76+
// THEN we expect the Location header to be set to the path of the created user resource
77+
.expect('Location', `/users/${payId}`)
78+
// AND we expect back a 201 - CREATED
79+
.expect(HttpStatus.Created, done)
80+
})
81+
5182
it('Returns a 201 when creating a new user, without an Accept-Patch header in the response', function (done): void {
5283
// GIVEN a user with a PayID known to not exist on the PayID service
5384
const userInformation = {

0 commit comments

Comments
 (0)