From 4ad04eecb18aacdf72fa64fcb704dec188ab07fe Mon Sep 17 00:00:00 2001 From: Nicolas Burtey Date: Sat, 16 Sep 2023 22:16:32 +0100 Subject: [PATCH] chore: almost work e2e --- apps/boltcard/bats/e2e-test.bats | 29 ++++- apps/boltcard/bats/gql/user-login.gql | 9 ++ .../boltcard/bats/gql/wallets-for-account.gql | 12 ++ apps/boltcard/bun.lockb | Bin 41699 -> 44784 bytes apps/boltcard/callback.ts | 114 +++++++++++++++++- apps/boltcard/config.ts | 2 + apps/boltcard/knex.ts | 17 +-- apps/boltcard/lnurlw.ts | 4 +- apps/boltcard/new.ts | 16 +-- apps/boltcard/package.json | 2 + 10 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 apps/boltcard/bats/gql/user-login.gql create mode 100644 apps/boltcard/bats/gql/wallets-for-account.gql diff --git a/apps/boltcard/bats/e2e-test.bats b/apps/boltcard/bats/e2e-test.bats index 1170e173814..9b30e642501 100644 --- a/apps/boltcard/bats/e2e-test.bats +++ b/apps/boltcard/bats/e2e-test.bats @@ -1,8 +1,15 @@ +load "../../../test/bats/helpers/setup-and-teardown" +load "../../../test/bats/helpers/ln" + +@test "auth: create user" { + login_user "alice" "+16505554321" "000000" +} @test "auth: create card" { - accountId="b12871e9-01e7-4aec-8597-873ebab7df1f" + echo "TOKEN_ALICE=$(read_value "alice")" + export TOKEN_ALICE=$(read_value "alice") - RESPONSE=$(curl -s "http://localhost:3000/createboltcard?accountId=${accountId}") + RESPONSE=$(curl -s "http://localhost:3000/createboltcard?token=${TOKEN_ALICE}") CALLBACK_URL=$(echo $RESPONSE | jq -r '.url') # Making the follow-up curl request @@ -11,9 +18,7 @@ [[ $(echo $RESPONSE | jq -r '.PROTOCOL_NAME') == "create_bolt_card_response" ]] || exit 1 } - @test "auth: create payment and follow up" { - P_VALUE="4E2E289D945A66BB13377A728884E867" C_VALUE="E19CCB1FED8892CE" @@ -26,6 +31,18 @@ echo "CALLBACK_URL: $CALLBACK_URL" echo "K1_VALUE: $K1_VALUE" - # Making the follow-up curl request - curl -s "${CALLBACK_URL}?k1=${K1_VALUE}" + cache_value "k1" "$K1_VALUE" + cache_value "CALLBACK_URL" "$CALLBACK_URL" } + +@test "callback" { + K1_VALUE=$(read_value "k1") + CALLBACK_URL=$(read_value "CALLBACK_URL") + + invoice_response="$(lnd_outside_2_cli addinvoice --amt 1000)" + payment_request=$(echo $invoice_response | jq -r '.payment_request') + echo $payment_request + + result=$(curl -s "${CALLBACK_URL}?k1=${K1_VALUE}&pr=${payment_request}") + [[ result.status == "OK" ]] || exit 1 +} \ No newline at end of file diff --git a/apps/boltcard/bats/gql/user-login.gql b/apps/boltcard/bats/gql/user-login.gql new file mode 100644 index 00000000000..44b1b124c09 --- /dev/null +++ b/apps/boltcard/bats/gql/user-login.gql @@ -0,0 +1,9 @@ +mutation userLogin($input: UserLoginInput!) { + userLogin(input: $input) { + errors { + code + message + } + authToken + } +} diff --git a/apps/boltcard/bats/gql/wallets-for-account.gql b/apps/boltcard/bats/gql/wallets-for-account.gql new file mode 100644 index 00000000000..e17a5ccf8f0 --- /dev/null +++ b/apps/boltcard/bats/gql/wallets-for-account.gql @@ -0,0 +1,12 @@ +query me { + me { + defaultAccount { + id + wallets { + id + walletCurrency + balance + } + } + } +} diff --git a/apps/boltcard/bun.lockb b/apps/boltcard/bun.lockb index 1adae7090c853bbbbe8361e671e6f2684a97f086..fd05e46c4d6d2ac8405b4cf399e2f717d63528ec 100755 GIT binary patch delta 8844 zcmeHNdt6l2_CM#y00$ie1Y`ge^(wxGr!qWb1`re(!B;gtibNOz1qPVmsWM=`diZK( zrKaVxw93buF^&7pC|AzU#~!CG*zpbNk%iAHTchd)8TN z@4fa~Yp=cMoU{G-h}3>sS{XHXT4i(Ai6L!k#*O*lzGuR|pLuQDyB=$E!v~b-l$z6) zEnYHXr=XO&RhB+sVYMzs5N6uS9EAndMU}-a$-}Ew^_hA=6a;@kXs&lyD~cfB0bUFK zF;HL7 zRtwcuyREF&D%5xiLLb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S$-DAS+3+b@q`+&=X1{6w?nv6Xb)0gQpKiM(OaQ&x$9F#?Ba_S5YyUR>3Y%i2OX8Ih$ z^wa2y6(_o0cyDhOYh(Wx6+HJ33`mN1BWi z=^yV%ldpx-$2+Vu^%G_1>fdi1p7YFe2sS4Sy7V*X51yZWB;wq%$$=iM?YuGM=&=Se z(9{zvUm8QZd#pD7w0iVYeXrlU?Y*Oc8CczFvS$8ciTe5VL!VyC_MdKA&JLrl;PBvB z3fcK3hxNqt?ktwo=%&e9dME8F3#2ekKd^r7dB;H2(peK&Vn%WrNdxtc9$)=S_or&brzWRo@LBikk7%l^zoyy( zdUyBYFRG5y&&o^3KK|;CHpjbvk6Lgn9o}QbD(v4=WYdqrd*3Xckw3BO1lJCNgb?{D zzBfkfA$#v#*B`G>l;KJ8_QuF7Vrf@zn&~`$b8wySrl0rbnr;MG + } + } | null +} + +type LnInvoicePaymentSendMutation = { + readonly __typename: "Mutation" + readonly lnInvoicePaymentSend: { + readonly __typename: "PaymentSendPayload" + readonly status?: string | null + readonly errors: ReadonlyArray<{ + readonly __typename: "GraphQLApplicationError" + readonly message: string + }> + } +} + +const getUsdWalletIdQuery = gql` + query getUsdWalletId { + me { + defaultAccount { + id + defaultWalletId + wallets { + id + walletCurrency + balance + } + } + } + } +` + +const lnInvoicePaymentSendMutation = gql` + mutation lnInvoicePaymentSend($input: LnInvoicePaymentInput!) { + lnInvoicePaymentSend(input: $input) { + errors { + message + } + status + } + } +` boltcardRouter.get("/callback", async (req: express.Request, res: express.Response) => { const k1 = req?.query?.k1 @@ -20,11 +88,47 @@ boltcardRouter.get("/callback", async (req: express.Request, res: express.Respon } const payment = await fetchByK1(k1) - console.log(payment) - // fetch user from k1 - // payInvoice(pr) + const { cardId } = payment + + const card = await fetchByCardId(cardId) + + const graphQLClient = new GraphQLClient(apiUrl, { + headers: { + authorization: `Bearer ${card.token}`, + }, + }) + + const data = await graphQLClient.request(getUsdWalletIdQuery) + const wallets = data.me?.defaultAccount.wallets - res.json({ status: "OK" }) + if (!wallets) { + res.status(400).send({ status: "ERROR", reason: "no wallets found" }) + return + } + + const usdWallet = wallets.find((wallet) => wallet.walletCurrency === "USD") + const usdWalletId = usdWallet?.id + + console.log({ usdWallet, wallets }) + + if (!usdWalletId) { + res.status(400).send({ status: "ERROR", reason: "no usd wallet found" }) + return + } + + const result = await graphQLClient.request({ + document: lnInvoicePaymentSendMutation, + variables: { input: { walletId: usdWalletId, paymentRequest: pr } }, + }) + + if (result.lnInvoicePaymentSend.status === "SUCCESS") { + res.json({ status: "OK" }) + } else { + res.status(400).send({ + status: "ERROR", + reason: `payment failed: ${result.lnInvoicePaymentSend.errors[0].message}`, + }) + } }) const callback = "dummy" diff --git a/apps/boltcard/config.ts b/apps/boltcard/config.ts index 03eb0d416dc..59bc0e4620a 100644 --- a/apps/boltcard/config.ts +++ b/apps/boltcard/config.ts @@ -1,5 +1,7 @@ export const serverUrl = process.env.SERVER_URL ?? "http://localhost:3000" +export const apiUrl = process.env.API_URL ?? "http://localhost:4002/graphql" + const AES_DECRYPT_KEY = process.env.AES_DECRYPT_KEY ?? "0c3b25d92b38ae443229dd59ad34b85d" export const aesDecryptKey = Buffer.from(AES_DECRYPT_KEY, "hex") diff --git a/apps/boltcard/knex.ts b/apps/boltcard/knex.ts index df953d44481..66736f23266 100644 --- a/apps/boltcard/knex.ts +++ b/apps/boltcard/knex.ts @@ -38,7 +38,8 @@ export async function createTable() { // if a card is resetted, the uid would stay the same table.string("uid").notNullable().index() - table.uuid("accountId").notNullable().index() + table.string("token").notNullable() + table.integer("ctr").notNullable() table.boolean("enabled").notNullable().defaultTo(true) @@ -59,7 +60,7 @@ export async function createTable() { table.string("oneTimeCode").notNullable().index().unique() table.timestamp("created_at").defaultTo(knex.fn.now()) table.string("status").defaultTo("init") // init, fetched, used - table.uuid("accountId").notNullable() + table.string("token").notNullable() table.string("k0AuthKey").notNullable() table.string("k2CmacKey").notNullable().index().unique() @@ -94,7 +95,7 @@ export async function fetchByCardId(cardId: string) { export interface CardInitInput { oneTimeCode: string - accountId: string + token: string k0AuthKey: string k2CmacKey: string k3: string @@ -103,7 +104,7 @@ export interface CardInitInput { export async function createCardInit(cardData: CardInitInput) { try { - const { oneTimeCode, k0AuthKey, k2CmacKey, k3, k4, accountId } = cardData + const { oneTimeCode, k0AuthKey, k2CmacKey, k3, k4, token } = cardData const result = await knex("CardInit").insert({ oneTimeCode, @@ -111,7 +112,7 @@ export async function createCardInit(cardData: CardInitInput) { k2CmacKey, k3, k4, - accountId, + token, }) return result @@ -128,12 +129,12 @@ interface CardInput { k3: string k4: string ctr: number - accountId: string + token: string } export async function createCard(cardData: CardInput) { try { - const { uid, k0AuthKey, k2CmacKey, k3, k4, ctr, accountId } = cardData + const { uid, k0AuthKey, k2CmacKey, k3, k4, ctr, token } = cardData const [result] = await knex("Card") .insert({ @@ -143,7 +144,7 @@ export async function createCard(cardData: CardInput) { k3, k4, ctr, - accountId, + token, }) .returning("*") diff --git a/apps/boltcard/lnurlw.ts b/apps/boltcard/lnurlw.ts index 6a822fc8a70..02359a9799e 100644 --- a/apps/boltcard/lnurlw.ts +++ b/apps/boltcard/lnurlw.ts @@ -99,10 +99,10 @@ boltcardRouter.get("/ln", async (req: express.Request, res: express.Response) => const result = await maybeSetupCard({ uidRaw, ctrRawInverseBytes, ba_c }) if (result) { - const { k0AuthKey, k2CmacKey, k3, k4, accountId } = result + const { k0AuthKey, k2CmacKey, k3, k4, token } = result await markCardInitAsUsed(k2CmacKey) - card = await createCard({ uid, k0AuthKey, k2CmacKey, k3, k4, ctr, accountId }) + card = await createCard({ uid, k0AuthKey, k2CmacKey, k3, k4, ctr, token }) } else { res.status(400).send({ status: "ERROR", reason: "card not found" }) return diff --git a/apps/boltcard/new.ts b/apps/boltcard/new.ts index 3f30299a01f..3bd56f27806 100644 --- a/apps/boltcard/new.ts +++ b/apps/boltcard/new.ts @@ -23,19 +23,21 @@ function randomHex(): string { boltcardRouter.get( "/createboltcard", async (req: express.Request, res: express.Response) => { - const accountId = req.query.accountId + // should be pass with POST? not sure if this would be compatible + // with the wallet that can create cards + const token = req.query.token - if (!accountId) { - res.status(400).send({ status: "ERROR", reason: "accountId missing" }) + if (!token) { + res.status(400).send({ status: "ERROR", reason: "token missing" }) return } - if (typeof accountId !== "string") { - res.status(400).send({ status: "ERROR", reason: "accountId is not a string" }) + if (typeof token !== "string") { + res.status(400).send({ status: "ERROR", reason: "token is not a string" }) return } - // TODO: accountId uuid validation + // TODO: token validation? const oneTimeCode = randomHex() const k0AuthKey = "0c3b25d92b38ae443229dd59ad34b85d" @@ -49,7 +51,7 @@ boltcardRouter.get( k2CmacKey, k3, k4, - accountId, + token, }) if (result instanceof Error) { diff --git a/apps/boltcard/package.json b/apps/boltcard/package.json index 7360c90c89d..9243867d93c 100644 --- a/apps/boltcard/package.json +++ b/apps/boltcard/package.json @@ -8,6 +8,8 @@ "aes-js": "^3.1.2", "body-parser": "^1.20.2", "express": "^4.18.2", + "graphql": "^16.8.0", + "graphql-request": "^6.1.0", "knex": "^2.5.1", "node-aes-cmac": "^0.1.1", "pg": "^8.11.3"