-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- AlterEnum | ||
ALTER TYPE "WalletType" ADD VALUE 'PHOENIXD'; | ||
|
||
-- CreateTable | ||
CREATE TABLE "WalletPhoenixd" ( | ||
"id" SERIAL NOT NULL, | ||
"walletId" INTEGER NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"url" TEXT NOT NULL, | ||
"secondaryPassword" TEXT NOT NULL, | ||
|
||
CONSTRAINT "WalletPhoenixd_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "WalletPhoenixd_walletId_key" ON "WalletPhoenixd"("walletId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "WalletPhoenixd" ADD CONSTRAINT "WalletPhoenixd_walletId_fkey" FOREIGN KEY ("walletId") REFERENCES "Wallet"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
CREATE TRIGGER wallet_phoenixd_as_jsonb | ||
AFTER INSERT OR UPDATE ON "WalletPhoenixd" | ||
FOR EACH ROW EXECUTE PROCEDURE wallet_wallet_type_as_jsonb(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export * from 'wallets/phoenixd' | ||
|
||
export async function testSendPayment (config, { logger }) { | ||
// TODO: | ||
// Not sure which endpoint to call to test primary password | ||
// see https://phoenix.acinq.co/server/api | ||
// Maybe just wait until test payments with HODL invoices? | ||
|
||
} | ||
|
||
export async function sendPayment (bolt11, { url, primaryPassword }) { | ||
// https://phoenix.acinq.co/server/api#pay-bolt11-invoice | ||
const path = '/payinvoice' | ||
|
||
const headers = new Headers() | ||
headers.set('Authorization', 'Basic ' + Buffer.from(':' + primaryPassword).toString('base64')) | ||
headers.set('Content-type', 'application/x-www-form-urlencoded') | ||
|
||
const body = new URLSearchParams() | ||
body.append('invoice', bolt11) | ||
|
||
const res = await fetch(url + path, { | ||
method: 'POST', | ||
headers, | ||
body | ||
}) | ||
if (!res.ok) { | ||
throw new Error(await res.text()) | ||
} | ||
|
||
const payment = await res.json() | ||
const preimage = payment.paymentPreimage | ||
if (!preimage) { | ||
throw new Error(payment.reason) | ||
} | ||
|
||
return payment.paymentPreimage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { phoenixdSchema } from '@/lib/validate' | ||
|
||
export const name = 'phoenixd' | ||
|
||
// configure wallet fields | ||
export const fields = [ | ||
{ | ||
name: 'url', | ||
label: 'url', | ||
type: 'text' | ||
}, | ||
{ | ||
name: 'primaryPassword', | ||
label: 'primary password', | ||
type: 'password', | ||
optional: 'for sending', | ||
help: 'You can find the primary password as `http-password` in your phoenixd configuration file as mentioned [here](https://phoenix.acinq.co/server/api#security).', | ||
clientOnly: true, | ||
editable: false | ||
}, | ||
{ | ||
name: 'secondaryPassword', | ||
label: 'secondary password', | ||
type: 'password', | ||
optional: 'for receiving', | ||
help: 'You can find the secondary password as `http-password-limited-access` in your phoenixd configuration file as mentioned [here](https://phoenix.acinq.co/server/api#security).', | ||
serverOnly: true, | ||
editable: false | ||
} | ||
] | ||
|
||
// configure wallet card | ||
export const card = { | ||
title: 'phoenixd', | ||
subtitle: 'use [phoenixd](https://phoenix.acinq.co/server) for payments', | ||
badges: ['send & receive'] | ||
} | ||
|
||
// phoenixd::TODO | ||
// set validation schema | ||
export const fieldValidation = phoenixdSchema | ||
|
||
export const walletType = 'PHOENIXD' | ||
|
||
export const walletField = 'walletPhoenixd' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { msatsToSats } from '@/lib/format' | ||
|
||
export * from 'wallets/phoenixd' | ||
|
||
export async function testCreateInvoice ({ url, secondaryPassword }) { | ||
return await createInvoice( | ||
{ msats: 1000, description: 'SN test invoice', expiry: 1 }, | ||
{ url, secondaryPassword }) | ||
} | ||
|
||
export async function createInvoice ( | ||
{ msats, description, descriptionHash, expiry }, | ||
{ url, secondaryPassword } | ||
) { | ||
// https://phoenix.acinq.co/server/api#create-bolt11-invoice | ||
const path = '/createinvoice' | ||
|
||
const headers = new Headers() | ||
headers.set('Authorization', 'Basic ' + Buffer.from(':' + secondaryPassword).toString('base64')) | ||
headers.set('Content-type', 'application/x-www-form-urlencoded') | ||
|
||
const body = new URLSearchParams() | ||
body.append('description', description) | ||
body.append('amountSat', msatsToSats(msats)) | ||
|
||
const res = await fetch(url + path, { | ||
method: 'POST', | ||
headers, | ||
body | ||
}) | ||
if (!res.ok) { | ||
const error = await res.text() | ||
throw new Error(error) | ||
} | ||
|
||
const payment = await res.json() | ||
return payment.serialized | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters