@rine-network/cli 0.15.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/main.js +203 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ npx @rine-network/cli onboard --email you@example.com --name "My Org" --slug my-
|
|
|
57
57
|
| `rine send / read / inbox / reply` | Messaging (with `--payload-file` for file/stdin input) |
|
|
58
58
|
| `rine wallet create / address / policy [set]` | Payment wallet and spend policy for x402 agent payments |
|
|
59
59
|
| `rine pay <message-id>` | Pay a received in-thread x402 quote (`--auto-pay`, `--no-marker`, `--force`) |
|
|
60
|
+
| `rine fulfill <message-id>` | Payee side: verify + settle a received x402 payment through a facilitator and reply with a receipt (`--facilitator <preset\|url>`, `--no-marker`) |
|
|
60
61
|
| `rine group ...` | Group CRUD, join, invite, vote, members |
|
|
61
62
|
| `rine webhook ...` | Outbound webhook management (rine → a URL you host) |
|
|
62
63
|
| `rine hook ... / rine relay` | Inbound webhook Funnel — hook CRUD + the relay daemon (`--tier zero-trust\|shared-edge`) |
|
package/dist/main.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { Command, Option } from "commander";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
|
-
import { FUNNEL_TIERS, HttpClient, IdempotencyStore, RineApiError, UUID_RE, X402Error, X402_MESSAGE_TYPE, addMlsGroupMember, agentKeysExist, agentLabel, buildIssueCertDeps, buildPaymentMessage, buildPaymentPayload, buildPaymentRequiredMessage, buildReceiptMessage, cacheToken, connectTunnel, createWallet, decryptGroupMessage, decryptMessage, decryptThreadRow, deleteHookSecret, encryptGroupMessage, encryptMessage, encryptMlsGroupMessage, ensureCert, externalJoinMlsGroup, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientKeys, formatError, fromBase64Url, generateAgentKeys, generateHookSecret, generatePqKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, getWalletAddress, handleWebhookRequest, hasSpiffeEndpoint, hookNameError, ingestSenderKeyDistribution, initMlsGroup, isAutoPayable, isBareAgentName, isX402MessageType, jitteredRefreshMargin, listMyInvites, loadAgentKeys, loadCredentials, loadHookSecret, loadMeta, loadMlsState, loadPolicy, loadTokenCache, loadWalletKey, makeEdgePipeFactory, normalizeHandle, parseX402Payload, performAgentCreation, performRegistration, processMlsWelcomes, readDailySpent, renewalDueWithJitter, reserveSpend, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveHookSecret, savePolicy, savePqEncryptionKey, saveTokenCache, selectRequirement, sendGroupInviteNotification, startTlsListener, syncMlsGroup, toBase64Url, validateEncryptionKey, validateSigningKey, validateSlug, verifyIdentitySpiffe, walletKeyExists } from "@rine-network/core";
|
|
5
|
+
import { FACILITATOR_PRESET, FUNNEL_TIERS, HttpClient, IdempotencyStore, RineApiError, UUID_RE, X402Error, X402FacilitatorError, X402_MESSAGE_TYPE, addMlsGroupMember, agentKeysExist, agentLabel, buildIssueCertDeps, buildPaymentMessage, buildPaymentPayload, buildPaymentRequiredMessage, buildReceiptMessage, cacheToken, connectTunnel, createWallet, decryptGroupMessage, decryptMessage, decryptThreadRow, deleteHookSecret, encryptGroupMessage, encryptMessage, encryptMlsGroupMessage, ensureCert, externalJoinMlsGroup, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientKeys, formatError, fromBase64Url, generateAgentKeys, generateHookSecret, generatePqKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, getWalletAddress, handleWebhookRequest, hasSpiffeEndpoint, hookNameError, ingestSenderKeyDistribution, initMlsGroup, isAutoPayable, isBareAgentName, isX402MessageType, jitteredRefreshMargin, listMyInvites, loadAgentKeys, loadCredentials, loadHookSecret, loadMeta, loadMlsState, loadPolicy, loadTokenCache, loadWalletKey, makeEdgePipeFactory, normalizeHandle, parseX402Payload, performAgentCreation, performRegistration, processMlsWelcomes, readDailySpent, renewalDueWithJitter, reserveSpend, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveHookSecret, savePolicy, savePqEncryptionKey, saveTokenCache, selectRequirement, sendGroupInviteNotification, settlePayment, startTlsListener, syncMlsGroup, toBase64Url, validateEncryptionKey, validateSigningKey, validateSlug, verifyIdentitySpiffe, verifyPayment, walletKeyExists } from "@rine-network/core";
|
|
6
6
|
import readline from "node:readline";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { resolve4 } from "node:dns/promises";
|
|
@@ -736,6 +736,207 @@ function registerDiscover(program) {
|
|
|
736
736
|
registerDiscoverGroups(discover, program);
|
|
737
737
|
}
|
|
738
738
|
//#endregion
|
|
739
|
+
//#region src/x402-facilitator.ts
|
|
740
|
+
/**
|
|
741
|
+
* Resolve a facilitator spec into a config. `spec` is either a preset key
|
|
742
|
+
* (`cdp` / `payai` / `x402-rs`) or an explicit `http(s)://` base URL. Optional
|
|
743
|
+
* auth headers (`"Key: Value"` strings) and verify/settle path overrides are
|
|
744
|
+
* merged in. Throws on an unrecognised spec so the caller fails loudly.
|
|
745
|
+
*/
|
|
746
|
+
function resolveFacilitator(spec, opts = {}) {
|
|
747
|
+
const base = FACILITATOR_PRESET[spec] ?? (/^https?:\/\//.test(spec) ? { url: spec } : void 0);
|
|
748
|
+
if (!base) throw new Error(`Unknown facilitator '${spec}'. Use a preset (${Object.keys(FACILITATOR_PRESET).join(" | ")}) or an http(s):// base URL.`);
|
|
749
|
+
const cfg = { url: base.url };
|
|
750
|
+
const headers = parseHeaders(opts.headers);
|
|
751
|
+
if (headers) cfg.headers = headers;
|
|
752
|
+
if (opts.verifyPath) cfg.verifyPath = opts.verifyPath;
|
|
753
|
+
if (opts.settlePath) cfg.settlePath = opts.settlePath;
|
|
754
|
+
return cfg;
|
|
755
|
+
}
|
|
756
|
+
function parseHeaders(raw) {
|
|
757
|
+
if (!raw || raw.length === 0) return void 0;
|
|
758
|
+
const headers = {};
|
|
759
|
+
for (const entry of raw) {
|
|
760
|
+
const idx = entry.indexOf(":");
|
|
761
|
+
if (idx === -1) throw new Error(`Malformed facilitator header '${entry}' (expected 'Key: Value').`);
|
|
762
|
+
headers[entry.slice(0, idx).trim()] = entry.slice(idx + 1).trim();
|
|
763
|
+
}
|
|
764
|
+
return headers;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* The settle-first ladder: verify the signed payment, and — only when valid —
|
|
768
|
+
* settle it. On an invalid verification, settlement is skipped and a
|
|
769
|
+
* `success:false` receipt body is synthesised so the payer still reaches a
|
|
770
|
+
* terminal `payment-failed`. A facilitator HTTP failure throws
|
|
771
|
+
* `X402FacilitatorError` (the caller surfaces it as a typed outcome).
|
|
772
|
+
*/
|
|
773
|
+
async function settleToReceipt(pp, facilitator, signal) {
|
|
774
|
+
const verification = await verifyPayment(pp, {
|
|
775
|
+
facilitator,
|
|
776
|
+
signal
|
|
777
|
+
});
|
|
778
|
+
if (verification.isValid) {
|
|
779
|
+
const settlement = await settlePayment(pp, {
|
|
780
|
+
facilitator,
|
|
781
|
+
signal
|
|
782
|
+
});
|
|
783
|
+
return {
|
|
784
|
+
status: settlement.success ? "settled" : "settlement-failed",
|
|
785
|
+
receiptBody: settlement
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
status: "verification-failed",
|
|
790
|
+
receiptBody: {
|
|
791
|
+
success: false,
|
|
792
|
+
transaction: "",
|
|
793
|
+
network: pp.accepted.network,
|
|
794
|
+
payer: pp.payload.authorization.from,
|
|
795
|
+
errorReason: verification.invalidReason ?? "verification_failed"
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/x402-receipt.ts
|
|
801
|
+
/**
|
|
802
|
+
* Build the `x402_receipt` message from the settlement body, HPKE-encrypt it to the
|
|
803
|
+
* PAYER (the payment's original sender), and reply in-thread as the payee. Returns
|
|
804
|
+
* the sent message. `emitMarker` toggles the cleartext `{status,rail}` marker.
|
|
805
|
+
*/
|
|
806
|
+
async function sendReceipt(params) {
|
|
807
|
+
const built = buildReceiptMessage(params.receiptBody, { emitMarker: params.emitMarker });
|
|
808
|
+
const recipientKeys = await fetchRecipientKeys(params.client, params.payerAgentId);
|
|
809
|
+
const encrypted = await encryptMessage(params.configDir, params.payeeAgentId, recipientKeys.encryption, built.payload, recipientKeys.pqEncryption);
|
|
810
|
+
const body = {
|
|
811
|
+
type: built.type,
|
|
812
|
+
content_type: built.content_type,
|
|
813
|
+
payload_schema: built.payload_schema,
|
|
814
|
+
...encrypted
|
|
815
|
+
};
|
|
816
|
+
if (built.metadata) body.metadata = built.metadata;
|
|
817
|
+
return await params.client.post(`/messages/${params.messageId}/reply`, body, { "X-Rine-Agent": params.payeeAgentId });
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Render the terminal fulfill outcome — JSON (machine) or a human table. The typed
|
|
821
|
+
* `status` (`settled` / `settlement-failed` / `verification-failed`) is authoritative;
|
|
822
|
+
* `sent` is the receipt message the payer will read.
|
|
823
|
+
*/
|
|
824
|
+
function reportFulfill(json, outcome, sent) {
|
|
825
|
+
const { status, receiptBody } = outcome;
|
|
826
|
+
if (json) {
|
|
827
|
+
printJson({
|
|
828
|
+
status,
|
|
829
|
+
receipt_id: sent.id,
|
|
830
|
+
conversation_id: sent.conversation_id,
|
|
831
|
+
success: receiptBody.success,
|
|
832
|
+
transaction: receiptBody.transaction || null,
|
|
833
|
+
network: receiptBody.network,
|
|
834
|
+
payer: receiptBody.payer
|
|
835
|
+
});
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
printTable([
|
|
839
|
+
{
|
|
840
|
+
Field: "Outcome",
|
|
841
|
+
Value: status
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
Field: "Receipt sent",
|
|
845
|
+
Value: sent.id
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
Field: "Conversation",
|
|
849
|
+
Value: sent.conversation_id
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
Field: "Settled",
|
|
853
|
+
Value: String(receiptBody.success)
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
Field: "Transaction",
|
|
857
|
+
Value: receiptBody.transaction || "—"
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
Field: "Network",
|
|
861
|
+
Value: receiptBody.network
|
|
862
|
+
}
|
|
863
|
+
]);
|
|
864
|
+
}
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region src/commands/fulfill.ts
|
|
867
|
+
function collectHeader(v, acc) {
|
|
868
|
+
acc.push(v);
|
|
869
|
+
return acc;
|
|
870
|
+
}
|
|
871
|
+
function registerFulfill(program) {
|
|
872
|
+
program.command("fulfill").description("Settle a received x402_payment via the facilitator and reply with an x402_receipt").argument("<message-id>", "ID of the received rine.v1.x402_payment").option("--agent <id>", "Payee agent ID (defaults to your agent)").option("--facilitator <preset|url>", "Facilitator preset (cdp | payai | x402-rs) or an http(s):// base URL", "payai").option("--facilitator-header <k:v>", "Auth header for the facilitator (repeatable), e.g. 'Authorization: Bearer …'", collectHeader, []).option("--verify-path <path>", "Override the facilitator /verify path").option("--settle-path <path>", "Override the facilitator /settle path").option("--no-marker", "Omit the cleartext status marker (fully sealed)").action(withClient(program, async ({ client, gOpts, configDir, apiUrl }, messageId, opts) => {
|
|
873
|
+
const message = await client.get(`/messages/${messageId}`);
|
|
874
|
+
if (message.type !== X402_MESSAGE_TYPE.PAYMENT) {
|
|
875
|
+
printError(`Message ${messageId} is '${message.type}', not ${X402_MESSAGE_TYPE.PAYMENT}. Nothing to fulfill.`);
|
|
876
|
+
process.exitCode = 2;
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
const payerAgentId = message.from_agent_id;
|
|
880
|
+
if (!payerAgentId) {
|
|
881
|
+
printError("Cannot fulfill: the payment has no resolvable sender.");
|
|
882
|
+
process.exitCode = 1;
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
const payeeAgentId = await resolveAgent(apiUrl, await fetchAgents(client), opts.agent, gOpts.as);
|
|
886
|
+
if (payeeAgentId === payerAgentId) {
|
|
887
|
+
printError("Cannot fulfill your own payment.");
|
|
888
|
+
process.exitCode = 1;
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (!agentKeysExist(configDir, payeeAgentId)) {
|
|
892
|
+
printError(`No E2EE keys for agent ${payeeAgentId}. Run 'rine keys generate' first.`);
|
|
893
|
+
process.exitCode = 1;
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
let facilitator;
|
|
897
|
+
try {
|
|
898
|
+
facilitator = resolveFacilitator(opts.facilitator, {
|
|
899
|
+
headers: opts.facilitatorHeader,
|
|
900
|
+
verifyPath: opts.verifyPath,
|
|
901
|
+
settlePath: opts.settlePath
|
|
902
|
+
});
|
|
903
|
+
} catch (err) {
|
|
904
|
+
printError(err instanceof Error ? err.message : String(err));
|
|
905
|
+
process.exitCode = 2;
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const decrypted = await decryptMessage(configDir, payeeAgentId, message.encrypted_payload, client);
|
|
909
|
+
const pp = parseX402Payload(message.type, decrypted.plaintext);
|
|
910
|
+
let outcome;
|
|
911
|
+
try {
|
|
912
|
+
outcome = await settleToReceipt(pp, facilitator);
|
|
913
|
+
} catch (err) {
|
|
914
|
+
if (err instanceof X402FacilitatorError) {
|
|
915
|
+
printError(`Facilitator error${err.status ? ` (${err.status})` : ""}: ${err.message}`);
|
|
916
|
+
if (gOpts.json) printJson({
|
|
917
|
+
status: "facilitator-error",
|
|
918
|
+
facilitator_status: err.status ?? null,
|
|
919
|
+
detail: err.message
|
|
920
|
+
});
|
|
921
|
+
process.exitCode = 1;
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
throw err;
|
|
925
|
+
}
|
|
926
|
+
const sent = await sendReceipt({
|
|
927
|
+
client,
|
|
928
|
+
configDir,
|
|
929
|
+
payeeAgentId,
|
|
930
|
+
payerAgentId,
|
|
931
|
+
messageId,
|
|
932
|
+
receiptBody: outcome.receiptBody,
|
|
933
|
+
emitMarker: opts.marker !== false
|
|
934
|
+
});
|
|
935
|
+
reportFulfill(Boolean(gOpts.json), outcome, sent);
|
|
936
|
+
if (outcome.status !== "settled") process.exitCode = 1;
|
|
937
|
+
}));
|
|
938
|
+
}
|
|
939
|
+
//#endregion
|
|
739
940
|
//#region src/commands/group.ts
|
|
740
941
|
async function installWelcomes(client, configDir, agentId, json) {
|
|
741
942
|
try {
|
|
@@ -2640,6 +2841,7 @@ registerWebhook(program);
|
|
|
2640
2841
|
registerHook(program);
|
|
2641
2842
|
registerWallet(program);
|
|
2642
2843
|
registerPay(program);
|
|
2844
|
+
registerFulfill(program);
|
|
2643
2845
|
registerKeys(program);
|
|
2644
2846
|
registerStream(program);
|
|
2645
2847
|
registerRelay(program);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rine-network/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "CLI client for rine.network \u2014 EU-first messaging infrastructure for AI agents",
|
|
5
5
|
"author": "mmmbs <mmmbs@proton.me>",
|
|
6
6
|
"license": "EUPL-1.2",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dev": "tsx src/main.ts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@rine-network/core": "^0.
|
|
31
|
+
"@rine-network/core": "^0.11.0",
|
|
32
32
|
"commander": "^12.0.0",
|
|
33
33
|
"eventsource-client": "^1.1.0"
|
|
34
34
|
},
|