From db0ea0b185b459dde5bf1a3fddd5855bb1c559d9 Mon Sep 17 00:00:00 2001 From: Nathan Lie Date: Tue, 16 Apr 2024 11:44:31 -0700 Subject: [PATCH] feat: update bruno collection --- ...ate Receiver (remote Incoming Payment).bru | 9 ++---- .../Rafiki/Rafiki Admin APIs/Create Asset.bru | 26 ++-------------- .../Create Incoming Payment.bru | 6 ++++ .../Create Or Update Peer By Url.bru | 6 ++++ .../Create Outgoing Payment.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Create Peer.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Create Quote.bru | 5 ++- ...ate Receiver (remote Incoming Payment).bru | 6 ++++ .../Create Wallet Address Key.bru | 6 ++++ .../Create Wallet Address Withdrawal.bru | 6 ++++ .../Create Wallet Address.bru | 3 ++ .../Rafiki/Rafiki Admin APIs/Delete Peer.bru | 6 ++++ .../Deposit Asset Liquidity.bru | 3 ++ .../Deposit Event Liquidity.bru | 6 ++++ .../Deposit Outgoing Payment Liquidity.bru | 3 ++ .../Deposit Peer Liquidity.bru | 3 ++ .../Rafiki/Rafiki Admin APIs/Get Asset.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Get Assets.bru | 6 ++++ .../Get Incoming Payment.bru | 6 ++++ .../Get Outgoing Payment.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Get Payments.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Get Peer.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Get Peers.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Get Quote.bru | 6 ++++ ...Get Receiver (remote Incoming Payment).bru | 6 ++++ .../Rafiki Admin APIs/Get Wallet Address.bru | 6 ++++ .../Get Wallet Addresses.bru | 6 ++++ .../Rafiki Admin APIs/Get Webhook Events.bru | 6 ++++ .../Post Liquidity Withdrawal.bru | 3 ++ .../Revoke Wallet Address Key.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Set Fee.bru | 6 ++++ .../Trigger Wallet Address Events.bru | 6 ++++ .../Rafiki/Rafiki Admin APIs/Update Asset.bru | 8 +++++ .../Rafiki/Rafiki Admin APIs/Update Peer.bru | 6 ++++ .../Update Wallet Address.bru | 6 ++++ .../Void Liquidity Withdrawal.bru | 3 ++ .../Withdraw Asset Liquidity.bru | 3 ++ .../Withdraw Event Liquidity.bru | 6 ++++ .../Withdraw Incoming Payment Liquidity.bru | 3 ++ .../Withdraw Outgoing Payment Liquidity.bru | 3 ++ .../Withdraw Peer Liquidity.bru | 3 ++ bruno/collections/Rafiki/bruno.json | 4 +-- .../Rafiki/environments/Local Playground.bru | 1 + bruno/collections/Rafiki/package.json | 3 +- bruno/collections/Rafiki/scripts.js | 31 +++++++++++++++++-- pnpm-lock.yaml | 9 ------ 46 files changed, 242 insertions(+), 46 deletions(-) diff --git a/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Cross Currency Payment/Create Receiver (remote Incoming Payment).bru b/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Cross Currency Payment/Create Receiver (remote Incoming Payment).bru index a78f774fe2..996c638643 100644 --- a/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Cross Currency Payment/Create Receiver (remote Incoming Payment).bru +++ b/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Cross Currency Payment/Create Receiver (remote Incoming Payment).bru @@ -10,10 +10,6 @@ post { auth: none } -headers { - Authorization: Bearer {{AdminApiToken}} -} - body:graphql { mutation CreateReceiver($input: CreateReceiverInput!) { createReceiver(input: $input) { @@ -70,12 +66,13 @@ script:pre-request { const body = req.getBody(); - console.log(body); + //console.log(body); const timestamp = Math.round(new Date().getTime() / 1000); const version = bru.getEnvVar('apiSignatureVersion'); const payload = `${timestamp}.${canonicalize(body)}`; - const hmac = createHmac('sha256', bru.getEnvVar('apiSignatureSecret')); + const secret = bru.getEnvVar('apiSignatureSecret') + const hmac = createHmac('sha256', secret) hmac.update(payload) const digest = hmac.digest('hex') diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru index 40f9d36cf2..4a39ff032b 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Asset.bru @@ -31,7 +31,7 @@ body:graphql { body:graphql:vars { { "input": { - "code": "USD", + "code": "JPY", "scale": 6, "withdrawalThreshold": null, "liquidityThreshold": "100000000" @@ -40,29 +40,9 @@ body:graphql:vars { } script:pre-request { - const { createHmac } = require('crypto'); - const { canonicalize } = require('json-canonicalize'); - const { print } = require('graphql/language/printer') + const scripts = require('./scripts'); - const body = req.getBody(); - const { query, variables, operationName } = body; - - //console.log(body); - - const formattedBody = { - variables, - query: print(query), - operationName - }; - - const timestamp = Math.round(new Date().getTime() / 1000); - const version = bru.getEnvVar('apiSignatureVersion'); - const payload = `${timestamp}.${canonicalize(formattedBody)}`; - const hmac = createHmac('sha256', bru.getEnvVar('apiSignatureSecret')); - hmac.update(payload) - const digest = hmac.digest('hex') - - req.setHeader('signature', `t=${timestamp}, v${version}=${digest}`) + scripts.addApiSignatureHeader(); } script:post-response { diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Incoming Payment.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Incoming Payment.bru index ead72840f7..d382f38253 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Incoming Payment.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Incoming Payment.bru @@ -52,6 +52,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Or Update Peer By Url.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Or Update Peer By Url.bru index 0cc080a15c..de6e5a43d8 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Or Update Peer By Url.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Or Update Peer By Url.bru @@ -40,6 +40,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Outgoing Payment.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Outgoing Payment.bru index 3b05e3e131..275ce0b1bc 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Outgoing Payment.bru @@ -79,6 +79,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru index 96eec58d01..f781efc61b 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Peer.bru @@ -49,6 +49,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru index 1530f4eab7..81fcd937ca 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru @@ -58,7 +58,8 @@ body:graphql:vars { script:pre-request { // Create an additional wallet address to represent the account that will be sending money - const fetch = require('node-fetch') + const fetch = require('node-fetch'); + const scripts = require('./scripts'); const randomInt = Math.floor(Math.random() * (1001)); @@ -82,6 +83,8 @@ script:pre-request { const response = await fetch(`${initialRequest.url}`, postRequest); const body = await response.json(); bru.setEnvVar("secondWalletAddressId", body.data.createWalletAddress.walletAddress.id); + + scripts.addApiSignatureHeader(); } script:post-response { diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Receiver (remote Incoming Payment).bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Receiver (remote Incoming Payment).bru index 2e295579e5..516e898d10 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Receiver (remote Incoming Payment).bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Receiver (remote Incoming Payment).bru @@ -57,6 +57,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Key.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Key.bru index 18c841ae3c..a803187bd9 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Key.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Key.bru @@ -48,6 +48,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + script:post-response { const body = res.getBody(); diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Withdrawal.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Withdrawal.bru index fffa11bd39..69721c5be7 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Withdrawal.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address Withdrawal.bru @@ -44,3 +44,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address.bru index 32f46e1b3b..ea8802ecc6 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address.bru @@ -46,8 +46,11 @@ body:graphql:vars { script:pre-request { const { nanoid } = require("nanoid"); + const scripts = require('./scripts'); bru.setVar('randomId', nanoid()); + + scripts.addApiSignatureHeader(); } script:post-response { diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Peer.bru index beaee1b827..bd8385b05c 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Delete Peer.bru @@ -28,3 +28,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Asset Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Asset Liquidity.bru index b8fac611e7..9718c60753 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Asset Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Asset Liquidity.bru @@ -35,7 +35,10 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("transferId",uuidv4()); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Event Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Event Liquidity.bru index e4410eadd7..cb8b566275 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Event Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Event Liquidity.bru @@ -29,3 +29,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Outgoing Payment Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Outgoing Payment Liquidity.bru index b8f571bced..112d7101b4 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Outgoing Payment Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Outgoing Payment Liquidity.bru @@ -33,6 +33,9 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Peer Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Peer Liquidity.bru index 29fe952b1c..84da018d9b 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Peer Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Deposit Peer Liquidity.bru @@ -35,7 +35,10 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("transferId",uuidv4()); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru index 93c7690159..c081990cf2 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Asset.bru @@ -40,3 +40,9 @@ body:graphql:vars { "id": "{{assetId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru index 3e4f00fe7b..f5df6ffcda 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Assets.bru @@ -55,3 +55,9 @@ body:graphql:vars { "last": null } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Incoming Payment.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Incoming Payment.bru index 6cfc959eae..4308a34e62 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Incoming Payment.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Incoming Payment.bru @@ -38,3 +38,9 @@ body:graphql:vars { "id": "{{incomingPaymentId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru index a953f0595f..21200aaad1 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru @@ -66,3 +66,9 @@ body:graphql:vars { "id": "{{outgoingPaymentId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Payments.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Payments.bru index 8ee443d2b5..23a3f1c4b2 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Payments.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Payments.bru @@ -40,3 +40,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru index b187c6567b..a062ae3bd5 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peer.bru @@ -26,3 +26,9 @@ body:graphql { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru index bf8cf85414..df7be544e3 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Peers.bru @@ -36,3 +36,9 @@ body:graphql { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Quote.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Quote.bru index 731fddefcf..2d92319182 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Quote.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Quote.bru @@ -41,3 +41,9 @@ body:graphql:vars { "id": "{{quoteId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Receiver (remote Incoming Payment).bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Receiver (remote Incoming Payment).bru index cf422888b9..675fea10e4 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Receiver (remote Incoming Payment).bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Receiver (remote Incoming Payment).bru @@ -39,3 +39,9 @@ body:graphql:vars { "id": "{{receiverId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Address.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Address.bru index 9bb51e4072..45a6da77a0 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Address.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Address.bru @@ -53,3 +53,9 @@ body:graphql:vars { "id": "{{walletAddressId}}" } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Addresses.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Addresses.bru index 712c40d35f..bc839a064b 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Addresses.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Wallet Addresses.bru @@ -24,3 +24,9 @@ body:graphql { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Webhook Events.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Webhook Events.bru index a7d29b9a60..2a542575f1 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Webhook Events.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Webhook Events.bru @@ -39,3 +39,9 @@ body:graphql:vars { "last": null } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Post Liquidity Withdrawal.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Post Liquidity Withdrawal.bru index f8bb4a66fe..f4916f076f 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Post Liquidity Withdrawal.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Post Liquidity Withdrawal.bru @@ -33,6 +33,9 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Revoke Wallet Address Key.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Revoke Wallet Address Key.bru index ae98271fd2..a8757f516d 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Revoke Wallet Address Key.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Revoke Wallet Address Key.bru @@ -33,3 +33,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Set Fee.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Set Fee.bru index 71d7c7995e..82f657bb2e 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Set Fee.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Set Fee.bru @@ -41,6 +41,12 @@ body:graphql:vars { } } +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} + tests { // } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Trigger Wallet Address Events.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Trigger Wallet Address Events.bru index 24502ab45b..9aef59aab0 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Trigger Wallet Address Events.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Trigger Wallet Address Events.bru @@ -28,3 +28,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru index 72b04ba972..3c70f63fbc 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Asset.bru @@ -37,3 +37,11 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); + + +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru index 597e814c6a..5d37f8c50a 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Peer.bru @@ -46,3 +46,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Wallet Address.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Wallet Address.bru index bfc0acadae..68f9024d9a 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Update Wallet Address.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Update Wallet Address.bru @@ -43,3 +43,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Void Liquidity Withdrawal.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Void Liquidity Withdrawal.bru index 7319c4c194..1e65b829d9 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Void Liquidity Withdrawal.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Void Liquidity Withdrawal.bru @@ -33,6 +33,9 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts') bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Asset Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Asset Liquidity.bru index ff563b7c5b..9d3a0ba5ba 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Asset Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Asset Liquidity.bru @@ -35,7 +35,10 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("transferId",uuidv4()); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Event Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Event Liquidity.bru index b962f03125..88d263a6b0 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Event Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Event Liquidity.bru @@ -29,3 +29,9 @@ body:graphql:vars { } } } + +script:pre-request { + const scripts = require('./scripts'); + + scripts.addApiSignatureHeader(); +} diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Incoming Payment Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Incoming Payment Liquidity.bru index 173388da95..84d6e1ca88 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Incoming Payment Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Incoming Payment Liquidity.bru @@ -32,6 +32,9 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Outgoing Payment Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Outgoing Payment Liquidity.bru index e674deb33b..89c742761c 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Outgoing Payment Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Outgoing Payment Liquidity.bru @@ -32,6 +32,9 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Peer Liquidity.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Peer Liquidity.bru index aee29be57d..145065ea81 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Peer Liquidity.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Withdraw Peer Liquidity.bru @@ -35,7 +35,10 @@ body:graphql:vars { script:pre-request { const { v4: uuidv4 } = require('uuid'); + const scripts = require('./scripts'); bru.setEnvVar("withdrawalId",uuidv4()); bru.setVar("idempotencyKey",uuidv4()); + + scripts.addApiSignatureHeader(); } diff --git a/bruno/collections/Rafiki/bruno.json b/bruno/collections/Rafiki/bruno.json index 0ff47b6731..6e5af81f62 100644 --- a/bruno/collections/Rafiki/bruno.json +++ b/bruno/collections/Rafiki/bruno.json @@ -4,8 +4,6 @@ "type": "collection", "ignore": ["node_modules", ".git"], "scripts": { - "moduleWhitelist": [ - "crypto" - ] + "moduleWhitelist": ["crypto"] } } diff --git a/bruno/collections/Rafiki/environments/Local Playground.bru b/bruno/collections/Rafiki/environments/Local Playground.bru index 326470288d..54b05cc61c 100644 --- a/bruno/collections/Rafiki/environments/Local Playground.bru +++ b/bruno/collections/Rafiki/environments/Local Playground.bru @@ -13,4 +13,5 @@ vars { clientPrivateKey: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1DNENBUUF3QlFZREsyVndCQ0lFSUVxZXptY1BoT0U4Ymt3TitqUXJwcGZSWXpHSWRGVFZXUUdUSEpJS3B6ODgKLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQo= apiSignatureVersion: 1 apiSignatureSecret: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964= + assetId: USD } diff --git a/bruno/collections/Rafiki/package.json b/bruno/collections/Rafiki/package.json index 6854525aa5..19c89c9996 100644 --- a/bruno/collections/Rafiki/package.json +++ b/bruno/collections/Rafiki/package.json @@ -1,8 +1,7 @@ { - "name": "Rafiki Bruno Collection", + "name": "rafiki-bruno-collection", "version": "1.0.0", "dependencies": { - "graphql": "^16.8.1", "json-canonicalize": "^1.0.6" } } diff --git a/bruno/collections/Rafiki/scripts.js b/bruno/collections/Rafiki/scripts.js index 262c97e48f..448d0acb1d 100644 --- a/bruno/collections/Rafiki/scripts.js +++ b/bruno/collections/Rafiki/scripts.js @@ -1,3 +1,5 @@ +const { createHmac } = require('crypto') +const { canonicalize } = require('json-canonicalize') const fetch = require('node-fetch') const url = require('url') @@ -5,7 +7,10 @@ const scripts = { sanitizeUrl: function () { return req .getUrl() - .replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key)) + .replace( + /{{([A-Za-z]\w+)}}/g, + (_, key) => bru.getVar(key) || bru.getEnvVar(key) + ) .replace(/localhost:([3,4])000/g, (_, key) => key === '3' ? bru.getEnvVar('host3000') : bru.getEnvVar('host4000') ) @@ -19,7 +24,10 @@ const scripts = { } return JSON.parse( requestBody - .replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key)) + .replace( + /{{([A-Za-z]\w+)}}/g, + (_, key) => bru.getVar(key) || bru.getEnvVar(key) + ) .replace(/http:\/\/localhost:([3,4])000/g, (_, key) => key === '3' ? 'https://' + bru.getEnvVar('host3000') @@ -74,6 +82,25 @@ const scripts = { this.setHeaders(signatureHeaders) }, + addApiSignatureHeader: function () { + const body = this.sanitizeBody() + const { variables } = body + const formattedBody = { + ...body, + variables: JSON.parse(variables) + } + + const timestamp = Math.round(new Date().getTime() / 1000) + const version = bru.getEnvVar('apiSignatureVersion') + const secret = bru.getEnvVar('apiSignatureSecret') + const payload = `${timestamp}.${canonicalize(formattedBody)}` + const hmac = createHmac('sha256', secret) + hmac.update(payload) + const digest = hmac.digest('hex') + + req.setHeader('signature', `t=${timestamp}, v${version}=${digest}`) + }, + addHostHeader: function (hostVarName) { const requestUrl = url.parse( req.getUrl().replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ef9d6d314..93b31627a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,15 +54,6 @@ importers: tigerbeetle-node: built: true - bruno/collections/Rafiki: - dependencies: - graphql: - specifier: ^16.8.1 - version: 16.8.1 - json-canonicalize: - specifier: ^1.0.6 - version: 1.0.6 - localenv/mock-account-servicing-entity: dependencies: '@apollo/client':