@perkos/agent-sdk 0.3.2 → 0.5.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.
@@ -0,0 +1,91 @@
1
+ import {
2
+ NayoriX402PaymentPolicy,
3
+ buildNayoriMppUnsignedPaymentTransaction,
4
+ createNayoriMppUsdcStacksChallenge,
5
+ createNayoriX402PaymentIntent,
6
+ createNayoriX402PaymentRequirements,
7
+ createNayoriX402Quote,
8
+ decodeNayoriMppChallengeHeader,
9
+ decodeNayoriMppUsdcStacksRequest,
10
+ } from "@perkos/agent-sdk";
11
+
12
+ const payer = "ST1THWXQ8368SDN2MJGE4BMDKMCHZ2GSVTSQDA7QF";
13
+ const payerPublicKey =
14
+ "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";
15
+ const payTo = "ST3AZN3BSQYJ5VWMNG92N88Z4G9498VYSHDZD9EK";
16
+ const now = Math.floor(Date.now() / 1_000);
17
+ const protectedRequest = {
18
+ method: "POST",
19
+ url: "https://api.nayori.ai/api/mpp/v1/research",
20
+ body: JSON.stringify({ topic: "Stacks agent commerce" }),
21
+ } as const;
22
+
23
+ const quote = await createNayoriX402Quote({
24
+ quoteId: "nq_mpp_quickstart_001",
25
+ merchantId: "merchant-research",
26
+ network: "testnet",
27
+ asset: "usdcx",
28
+ amount: 100_000n,
29
+ payTo,
30
+ ...protectedRequest,
31
+ issuedAt: now,
32
+ expiresAt: now + 300,
33
+ });
34
+ const challenge = await createNayoriMppUsdcStacksChallenge({
35
+ quote,
36
+ realm: "api.nayori.ai",
37
+ description: "Nayori agent research request",
38
+ });
39
+ const paymentRequirements = await createNayoriX402PaymentRequirements(quote);
40
+ const intent = await createNayoriX402PaymentIntent({
41
+ quote,
42
+ paymentRequirements,
43
+ request: protectedRequest,
44
+ payer,
45
+ publicKey: payerPublicKey,
46
+ fee: 300n,
47
+ nonce: 0n,
48
+ nowSeconds: now,
49
+ });
50
+ const policy = new NayoriX402PaymentPolicy(
51
+ {
52
+ allowedNetworks: ["testnet"],
53
+ allowedAssets: ["usdcx"],
54
+ allowedRecipients: [payTo],
55
+ allowedOrigins: ["https://api.nayori.ai"],
56
+ allowedMerchantIds: ["merchant-research"],
57
+ maxPerTransaction: { usdcx: 100_000n },
58
+ maxPerSession: { usdcx: 500_000n },
59
+ maxFeePerTransaction: 500n,
60
+ maxFeePerSession: 2_500n,
61
+ },
62
+ () => now
63
+ );
64
+ const authorization = policy.reserve(intent);
65
+ const unsignedTransaction = await buildNayoriMppUnsignedPaymentTransaction(intent);
66
+ const parsedChallenge = decodeNayoriMppChallengeHeader(challenge.wwwAuthenticate);
67
+ const paymentRequest = decodeNayoriMppUsdcStacksRequest(parsedChallenge.request);
68
+
69
+ console.log(
70
+ JSON.stringify(
71
+ {
72
+ status: "ready-for-wallet-signature",
73
+ protocol: "MPP PaymentAuth",
74
+ challengeHeader: parsedChallenge.header,
75
+ method: parsedChallenge.method,
76
+ intent: parsedChallenge.intent,
77
+ profile: paymentRequest.methodDetails.type,
78
+ network: paymentRequest.methodDetails.stacks.network,
79
+ currency: paymentRequest.currency,
80
+ amount: paymentRequest.amount,
81
+ unsignedTransactionBytes: unsignedTransaction.length / 2,
82
+ policyRemaining: authorization.remainingThisSession.toString(),
83
+ walletBroadcast: false,
84
+ serverSettlementRequired: true,
85
+ },
86
+ null,
87
+ 2
88
+ )
89
+ );
90
+
91
+ authorization.release();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkos/agent-sdk",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript SDK for agent identity, escrow settlement, and reputation on Stacks.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,6 +35,8 @@
35
35
  "quickstart:x402:facilitator": "node --import tsx examples/x402-facilitator.ts",
36
36
  "prequickstart:x402:payer": "npm run build",
37
37
  "quickstart:x402:payer": "node --import tsx examples/x402-payment-intent.ts",
38
+ "prequickstart:mpp": "npm run build",
39
+ "quickstart:mpp": "node --import tsx examples/mpp-usdcx.ts",
38
40
  "prequickstart:testnet": "npm run build",
39
41
  "quickstart:testnet": "node --import tsx examples/testnet-lifecycle.ts"
40
42
  },
@@ -49,8 +51,12 @@
49
51
  "keywords": [
50
52
  "ai-agents",
51
53
  "agentic-commerce",
54
+ "mpp",
55
+ "paymentauth",
52
56
  "stacks",
53
57
  "sbtc",
58
+ "usdcx",
59
+ "x402",
54
60
  "escrow",
55
61
  "bitcoin"
56
62
  ],