@rine-network/cli 0.15.1 → 0.16.1
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 +196 -2
- 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 { 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, matchedQuoteToWire, normalizeHandle, parseFacilitatorHeaders, parseX402Payload, performAgentCreation, performRegistration, processMlsWelcomes, readDailySpent, refusalReceiptBody, renewalDueWithJitter, reserveSpend, resolveAgent, resolveApiUrl, resolveConfigDir, resolveFacilitatorConfig, resolveHandleViaWebFinger, resolvePayeeRequirement, resolveToUuid, saveAgentKeys, saveCredentials, saveHookSecret, savePolicy, savePqEncryptionKey, saveTokenCache, selectRequirement, sendGroupInviteNotification, sendReceipt, settleToReceipt, startTlsListener, syncMlsGroup, toBase64Url, validateEncryptionKey, validateSigningKey, validateSlug, verifyIdentitySpiffe, 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,199 @@ function registerDiscover(program) {
|
|
|
736
736
|
registerDiscoverGroups(discover, program);
|
|
737
737
|
}
|
|
738
738
|
//#endregion
|
|
739
|
+
//#region src/x402-receipt.ts
|
|
740
|
+
/**
|
|
741
|
+
* Render the terminal fulfill outcome — JSON (machine) or a human table. The typed
|
|
742
|
+
* `status` (`settled` / `settlement-failed` / `verification-failed`) is authoritative;
|
|
743
|
+
* `sent` is the receipt message the payer will read. The `matchedQuote` (the
|
|
744
|
+
* payee-issued quote the payment answered — `message_id` `null` for an operator
|
|
745
|
+
* override) is surfaced so an integration can bind the good it delivers to the
|
|
746
|
+
* quote that was actually reconciled + settled.
|
|
747
|
+
*/
|
|
748
|
+
function reportFulfill(json, outcome, sent) {
|
|
749
|
+
const { status, receiptBody, matchedQuote } = outcome;
|
|
750
|
+
if (json) {
|
|
751
|
+
printJson({
|
|
752
|
+
status,
|
|
753
|
+
receipt_id: sent.id,
|
|
754
|
+
conversation_id: sent.conversation_id,
|
|
755
|
+
success: receiptBody.success,
|
|
756
|
+
transaction: receiptBody.transaction || null,
|
|
757
|
+
network: receiptBody.network,
|
|
758
|
+
payer: receiptBody.payer,
|
|
759
|
+
matched_quote: matchedQuoteToWire(matchedQuote)
|
|
760
|
+
});
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
printTable([
|
|
764
|
+
{
|
|
765
|
+
Field: "Outcome",
|
|
766
|
+
Value: status
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
Field: "Receipt sent",
|
|
770
|
+
Value: sent.id
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
Field: "Conversation",
|
|
774
|
+
Value: sent.conversation_id
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
Field: "Settled",
|
|
778
|
+
Value: String(receiptBody.success)
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
Field: "Transaction",
|
|
782
|
+
Value: receiptBody.transaction || "—"
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
Field: "Network",
|
|
786
|
+
Value: receiptBody.network
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
Field: "Quote",
|
|
790
|
+
Value: matchedQuote.quoteMessageId ?? "(operator override)"
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
Field: "Quote amount",
|
|
794
|
+
Value: `${matchedQuote.amount} ${matchedQuote.asset}`
|
|
795
|
+
}
|
|
796
|
+
]);
|
|
797
|
+
}
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/commands/fulfill.ts
|
|
800
|
+
function collectHeader(v, acc) {
|
|
801
|
+
acc.push(v);
|
|
802
|
+
return acc;
|
|
803
|
+
}
|
|
804
|
+
function registerFulfill(program) {
|
|
805
|
+
program.command("fulfill").description("Settle a received x402_payment via the facilitator and reply with an x402_receipt. The payment is bound to the ONE payee-issued x402_payment_required quote it references (the signed quoteMessageId) and reconciled against THAT quote (payTo/amount/asset/network/scheme) — the payer's echoed terms are never trusted. A payment carrying no/forged/cross-conversation quote reference REFUSES to settle (fail closed) unless explicit expected terms (--pay-to/--expect-amount/--expect-asset/--expect-network) authorise an out-of-band quote.").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("--pay-to <address>", "Out-of-band quote: expected payee wallet (0x). Requires --expect-amount/--expect-asset/--expect-network; overrides the referenced quote (no quoteMessageId needed)").option("--expect-amount <major>", "Out-of-band quote: expected amount in MAJOR units (e.g. 1.00). Overpayment is accepted, underpayment refused").option("--expect-asset <address>", "Out-of-band quote: expected token contract (0x)").option("--expect-network <caip2>", "Out-of-band quote: expected CAIP-2 network (e.g. eip155:8453)").option("--no-marker", "Omit the cleartext status marker (fully sealed)").action(withClient(program, async ({ client, gOpts, configDir, apiUrl }, messageId, opts) => {
|
|
806
|
+
const message = await client.get(`/messages/${messageId}`);
|
|
807
|
+
if (message.type !== X402_MESSAGE_TYPE.PAYMENT) {
|
|
808
|
+
printError(`Message ${messageId} is '${message.type}', not ${X402_MESSAGE_TYPE.PAYMENT}. Nothing to fulfill.`);
|
|
809
|
+
process.exitCode = 2;
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
const payerAgentId = message.from_agent_id;
|
|
813
|
+
if (!payerAgentId) {
|
|
814
|
+
printError("Cannot fulfill: the payment has no resolvable sender.");
|
|
815
|
+
process.exitCode = 1;
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
const payeeAgentId = await resolveAgent(apiUrl, await fetchAgents(client), opts.agent, gOpts.as);
|
|
819
|
+
if (payeeAgentId === payerAgentId) {
|
|
820
|
+
printError("Cannot fulfill your own payment.");
|
|
821
|
+
process.exitCode = 1;
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (!agentKeysExist(configDir, payeeAgentId)) {
|
|
825
|
+
printError(`No E2EE keys for agent ${payeeAgentId}. Run 'rine keys generate' first.`);
|
|
826
|
+
process.exitCode = 1;
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
let facilitator;
|
|
830
|
+
try {
|
|
831
|
+
facilitator = resolveFacilitatorConfig(opts.facilitator, {
|
|
832
|
+
headers: parseFacilitatorHeaders(opts.facilitatorHeader),
|
|
833
|
+
verifyPath: opts.verifyPath,
|
|
834
|
+
settlePath: opts.settlePath
|
|
835
|
+
});
|
|
836
|
+
} catch (err) {
|
|
837
|
+
printError(err instanceof Error ? err.message : String(err));
|
|
838
|
+
process.exitCode = 2;
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const decrypted = await decryptMessage(configDir, payeeAgentId, message.encrypted_payload, client);
|
|
842
|
+
let pp;
|
|
843
|
+
try {
|
|
844
|
+
pp = parseX402Payload(message.type, decrypted.plaintext);
|
|
845
|
+
} catch (err) {
|
|
846
|
+
if (!(err instanceof X402Error)) throw err;
|
|
847
|
+
const sent = await sendReceipt({
|
|
848
|
+
client,
|
|
849
|
+
configDir,
|
|
850
|
+
payeeAgentId,
|
|
851
|
+
payerAgentId,
|
|
852
|
+
messageId,
|
|
853
|
+
receiptBody: refusalReceiptBody("", "", err.code),
|
|
854
|
+
emitMarker: opts.marker !== false
|
|
855
|
+
});
|
|
856
|
+
printError(`Malformed payment payload: ${err.message}`);
|
|
857
|
+
if (gOpts.json) printJson({
|
|
858
|
+
status: "malformed-payload",
|
|
859
|
+
code: err.code,
|
|
860
|
+
detail: err.message,
|
|
861
|
+
receipt_id: sent.id
|
|
862
|
+
});
|
|
863
|
+
process.exitCode = 1;
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
let resolved;
|
|
867
|
+
try {
|
|
868
|
+
resolved = await resolvePayeeRequirement({
|
|
869
|
+
payment: pp,
|
|
870
|
+
expected: {
|
|
871
|
+
payTo: opts.payTo,
|
|
872
|
+
expectAmount: opts.expectAmount,
|
|
873
|
+
expectAsset: opts.expectAsset,
|
|
874
|
+
expectNetwork: opts.expectNetwork
|
|
875
|
+
},
|
|
876
|
+
client,
|
|
877
|
+
configDir,
|
|
878
|
+
payeeAgentId,
|
|
879
|
+
conversationId: message.conversation_id
|
|
880
|
+
});
|
|
881
|
+
} catch (err) {
|
|
882
|
+
if (!(err instanceof X402Error)) throw err;
|
|
883
|
+
const sent = await sendReceipt({
|
|
884
|
+
client,
|
|
885
|
+
configDir,
|
|
886
|
+
payeeAgentId,
|
|
887
|
+
payerAgentId,
|
|
888
|
+
messageId,
|
|
889
|
+
receiptBody: refusalReceiptBody(pp.accepted.network, pp.payload.authorization.from, err.code),
|
|
890
|
+
emitMarker: opts.marker !== false
|
|
891
|
+
});
|
|
892
|
+
printError(`Refusing to settle: ${err.message}`);
|
|
893
|
+
if (gOpts.json) printJson({
|
|
894
|
+
status: "payment-refused",
|
|
895
|
+
code: err.code,
|
|
896
|
+
detail: err.message,
|
|
897
|
+
receipt_id: sent.id
|
|
898
|
+
});
|
|
899
|
+
process.exitCode = 1;
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
let outcome;
|
|
903
|
+
try {
|
|
904
|
+
outcome = await settleToReceipt(pp, resolved, facilitator);
|
|
905
|
+
} catch (err) {
|
|
906
|
+
if (err instanceof X402FacilitatorError) {
|
|
907
|
+
printError(`Facilitator error${err.status ? ` (${err.status})` : ""}: ${err.message}`);
|
|
908
|
+
if (gOpts.json) printJson({
|
|
909
|
+
status: "facilitator-error",
|
|
910
|
+
facilitator_status: err.status ?? null,
|
|
911
|
+
detail: err.message
|
|
912
|
+
});
|
|
913
|
+
process.exitCode = 1;
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
throw err;
|
|
917
|
+
}
|
|
918
|
+
const sent = await sendReceipt({
|
|
919
|
+
client,
|
|
920
|
+
configDir,
|
|
921
|
+
payeeAgentId,
|
|
922
|
+
payerAgentId,
|
|
923
|
+
messageId,
|
|
924
|
+
receiptBody: outcome.receiptBody,
|
|
925
|
+
emitMarker: opts.marker !== false
|
|
926
|
+
});
|
|
927
|
+
reportFulfill(Boolean(gOpts.json), outcome, sent);
|
|
928
|
+
if (outcome.status !== "settled") process.exitCode = 1;
|
|
929
|
+
}));
|
|
930
|
+
}
|
|
931
|
+
//#endregion
|
|
739
932
|
//#region src/commands/group.ts
|
|
740
933
|
async function installWelcomes(client, configDir, agentId, json) {
|
|
741
934
|
try {
|
|
@@ -1737,7 +1930,7 @@ function registerPay(program) {
|
|
|
1737
1930
|
return;
|
|
1738
1931
|
}
|
|
1739
1932
|
}
|
|
1740
|
-
const built = buildPaymentMessage(buildPaymentPayload(pr, requirement, loadWalletKey(configDir, payerAgentId)), { emitMarker: opts.marker !== false });
|
|
1933
|
+
const built = buildPaymentMessage(buildPaymentPayload(pr, requirement, loadWalletKey(configDir, payerAgentId), { quoteMessageId: messageId }), { emitMarker: opts.marker !== false });
|
|
1741
1934
|
const recipientKeys = await fetchRecipientKeys(client, payeeAgentId);
|
|
1742
1935
|
const encrypted = await encryptMessage(configDir, payerAgentId, recipientKeys.encryption, built.payload, recipientKeys.pqEncryption);
|
|
1743
1936
|
const body = {
|
|
@@ -2640,6 +2833,7 @@ registerWebhook(program);
|
|
|
2640
2833
|
registerHook(program);
|
|
2641
2834
|
registerWallet(program);
|
|
2642
2835
|
registerPay(program);
|
|
2836
|
+
registerFulfill(program);
|
|
2643
2837
|
registerKeys(program);
|
|
2644
2838
|
registerStream(program);
|
|
2645
2839
|
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.1",
|
|
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.1",
|
|
32
32
|
"commander": "^12.0.0",
|
|
33
33
|
"eventsource-client": "^1.1.0"
|
|
34
34
|
},
|