lnpay/php-lndconnect

LNDConnect 规范的 PHP 实现

dev-master 2020-07-24 19:01 UTC

This package is auto-updated.

Last update: 2024-08-25 04:17:31 UTC


README

standard-readme compliant

生成和解析 lndconnect uri https://github.com/LN-Zap/lndconnect ⚡️

此包提供用于在 PHP 中生成和解析 lndconnect uri 的工具。

更多信息请参阅 uri 格式规范

目录

安装

composer require lnpay/php-lndconnect

使用方法

LndConnect::format($host,$encoded_cert,$base64url_macaroon);

将主机 / 证书 / macaroon 组合格式化为 lndconnect 链接。

use LndConnect\LndConnect;

LndConnect::format('127.0.0.1:10009','MIICuDCCAl...','AgEDbG5kAus...');

//lndconnect://127.0.0.1:10009?cert=MIICuDCCAl...&macaroon=AgEDbG5kAus...')

LndConnect::encode($host,$raw_cert,$macaroon_hex);

将主机 / 证书 / macaroon 组合并编码,然后格式化为 lndconnect 链接。

use LndConnect\LndConnect;

LndConnect::encode('127.0.0.1:10009','-----BEGIN CERTIFICATE-----...','0201036c6...');

//lndconnect://127.0.0.1:10009?cert=MIICuDCCAl...&macaroon=AgEDbG5kAus...')

LndConnect::decode($lndconnect_uri);

将 lndconnect 链接解码为其组成部分(主机 / 证书作为 utf8 / macaroon 作为十六进制)。

use LndConnect\LndConnect;

LndConnect::decode('lndconnect://127.0.0.1:10001?cert=MIICDjCCAbSgAwI&macaroon=AgEDbG5');

/*
 * [
 *   'host' => '127.0.0.1:10001',
 *   'cert => '-----BEGIN CERTIFICATE-----.....',
 *   'macaroon'=>'0201036c6....'
 * ]
 */

证书

LndConnect::encodeCert($raw_cert)

将证书字符串编码为 base64url 编码的 DER 格式。

use LndConnect\LndConnect;

LndConnect::encodeCert('-----BEGIN CERTIFICATE-----\n.....');

//MIICDjCCAbSgAwI

LndConnect::decodeCert($lndconnect_cert)

将 base64url 编码的 DER 格式证书解码为字符串。

use LndConnect\LndConnect;

LndConnect::decodeCert('MIICDjCCAbSgAwI');

//-----BEGIN CERTIFICATE-----\n.....

Macaroon

LndConnect::encodeMacaroon($macaroon_hex)

将二进制 macaroon 十六进制编码为 base64url 编码的字符串。

use LndConnect\LndConnect;

LndConnect::encodeMacaroon('0201036c6...');

//AgEDbG5kAus...

LndConnect::decodeMacaroon($lndconnect_macaroon)

将 base64url 编码的 macaroon 解码为十六进制编码的 macaroon。

use LndConnect\LndConnect;

LndConnect::decodeMacaroon('AgEDbG5kAus...');

//0201036c6...

测试

运行测试套件

  vendor/bin/phpunit

维护者

Tim Kijewski (tkijewski).

贡献

请随意深入了解!打开问题或提交 PR。

lndconnect 遵循 贡献者公约 行为准则。

许可

MIT © Tim Kijewski