@dakota-xyz/ts-sdk 1.4.0 → 2.0.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 +122 -0
- package/dist/index.d.mts +1352 -46
- package/dist/index.d.ts +1352 -46
- package/dist/index.js +840 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +821 -32
- package/dist/index.mjs.map +1 -1
- package/dist/webhook/index.d.mts +141 -7
- package/dist/webhook/index.d.ts +141 -7
- package/dist/webhook/index.js +9 -2
- package/dist/webhook/index.js.map +1 -1
- package/dist/webhook/index.mjs +9 -2
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { randomUUID, generateKeyPairSync, createPrivateKey, createPublicKey, createSign, createVerify } from 'crypto';
|
|
2
|
+
|
|
1
3
|
// src/client/environment.ts
|
|
2
4
|
var Environment = /* @__PURE__ */ ((Environment2) => {
|
|
3
5
|
Environment2["Sandbox"] = "sandbox";
|
|
@@ -227,7 +229,7 @@ function resolveConfig(config) {
|
|
|
227
229
|
// src/client/transport.ts
|
|
228
230
|
var RETRYABLE_STATUS_CODES2 = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
229
231
|
var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
|
|
230
|
-
var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
232
|
+
var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
231
233
|
var Transport = class {
|
|
232
234
|
config;
|
|
233
235
|
constructor(config) {
|
|
@@ -612,6 +614,15 @@ var CustomersResource = class extends BaseResource {
|
|
|
612
614
|
* { idempotencyKey: 'create-acme-corp-001' }
|
|
613
615
|
* );
|
|
614
616
|
* console.log(customer.applicationUrl); // KYB onboarding URL
|
|
617
|
+
*
|
|
618
|
+
* // Designate as a sub-client at creation (ENG-2454).
|
|
619
|
+
* // `is_sub_client` can only be set here — a regular customer cannot
|
|
620
|
+
* // be promoted afterwards. Cannot be combined with `sub_client_id`.
|
|
621
|
+
* const subClient = await client.customers.create({
|
|
622
|
+
* name: 'Partner Corp',
|
|
623
|
+
* customer_type: 'business',
|
|
624
|
+
* is_sub_client: true,
|
|
625
|
+
* });
|
|
615
626
|
* ```
|
|
616
627
|
*/
|
|
617
628
|
async create(data, options) {
|
|
@@ -854,30 +865,39 @@ var DestinationsResource = class extends BaseResource {
|
|
|
854
865
|
/**
|
|
855
866
|
* Create a new destination for a recipient.
|
|
856
867
|
*
|
|
857
|
-
* Destinations can be bank accounts (fiat_us) or crypto
|
|
868
|
+
* Destinations can be bank accounts (fiat_us / fiat_iban) or crypto
|
|
869
|
+
* wallets (crypto).
|
|
870
|
+
*
|
|
871
|
+
* The platform returns just `{ id }` here (per `IDResponse`), not the
|
|
872
|
+
* full destination object. Call `destinations.list(recipientId)` if
|
|
873
|
+
* you need the rest of the fields.
|
|
858
874
|
*
|
|
859
875
|
* @param recipientId - Recipient ID
|
|
860
876
|
* @param data - Destination creation data
|
|
861
|
-
* @returns
|
|
877
|
+
* @returns `{ id }` of the newly-created destination
|
|
862
878
|
*
|
|
863
879
|
* @example
|
|
864
880
|
* ```typescript
|
|
865
|
-
* //
|
|
866
|
-
* const bankDest = await client.destinations.create(recipientId, {
|
|
867
|
-
* destination_type: 'fiat_us',
|
|
868
|
-
* bank_name: 'Chase Bank',
|
|
869
|
-
* account_holder_name: 'Acme Corp',
|
|
870
|
-
* account_number: '123456789',
|
|
871
|
-
* routing_number: '021000021',
|
|
872
|
-
* account_type: 'checking',
|
|
873
|
-
* });
|
|
874
|
-
*
|
|
875
|
-
* // Create a crypto destination (for on-ramp)
|
|
881
|
+
* // Crypto destination (for on-ramp)
|
|
876
882
|
* const cryptoDest = await client.destinations.create(recipientId, {
|
|
877
883
|
* destination_type: 'crypto',
|
|
884
|
+
* name: 'Treasury USDC',
|
|
878
885
|
* crypto_address: '0x742d35Cc6634C0532925a3b844Bc9e7595f...',
|
|
879
886
|
* network_id: 'ethereum-mainnet',
|
|
880
887
|
* });
|
|
888
|
+
* // → cryptoDest.id
|
|
889
|
+
*
|
|
890
|
+
* // Fiat US destination (for off-ramp)
|
|
891
|
+
* const bankDest = await client.destinations.create(recipientId, {
|
|
892
|
+
* destination_type: 'fiat_us',
|
|
893
|
+
* name: 'Acme Chase Checking',
|
|
894
|
+
* bank_name: 'JPMorgan Chase',
|
|
895
|
+
* account_holder_name: 'Acme Corp',
|
|
896
|
+
* account_number: '000123456789',
|
|
897
|
+
* aba_routing_number: '021000021',
|
|
898
|
+
* account_type: 'checking',
|
|
899
|
+
* });
|
|
900
|
+
* // → bankDest.id
|
|
881
901
|
* ```
|
|
882
902
|
*/
|
|
883
903
|
async create(recipientId, data, options) {
|
|
@@ -1113,6 +1133,13 @@ var TransactionsResource = class extends BaseResource {
|
|
|
1113
1133
|
* customer_id: customerId,
|
|
1114
1134
|
* status: 'completed',
|
|
1115
1135
|
* });
|
|
1136
|
+
*
|
|
1137
|
+
* // Wallet-scoped filters (require transaction_type: 'wallet')
|
|
1138
|
+
* const sent = client.transactions.list({
|
|
1139
|
+
* transaction_type: 'wallet',
|
|
1140
|
+
* wallet_id: walletId,
|
|
1141
|
+
* direction: 'out',
|
|
1142
|
+
* });
|
|
1116
1143
|
* ```
|
|
1117
1144
|
*/
|
|
1118
1145
|
list(params) {
|
|
@@ -1254,40 +1281,76 @@ var WalletsResource = class extends BaseResource {
|
|
|
1254
1281
|
/**
|
|
1255
1282
|
* Get wallet balances.
|
|
1256
1283
|
*
|
|
1284
|
+
* Returns the platform's full `WalletBalances` response: the wallet id,
|
|
1285
|
+
* its on-chain address, every per-asset balance, and a pre-computed
|
|
1286
|
+
* `total_amount_usd` across all assets. The previous return shape
|
|
1287
|
+
* (`WalletBalance[]`) silently dropped `address` and `total_amount_usd`,
|
|
1288
|
+
* forcing callers to do a second `wallets.get()` and sum the balances
|
|
1289
|
+
* by hand. This is a small breaking change with a one-line migration
|
|
1290
|
+
* (`balances` → `balances.balances`); the prior shape had been broken
|
|
1291
|
+
* since 1.3.x anyway.
|
|
1292
|
+
*
|
|
1257
1293
|
* @param walletId - Wallet ID
|
|
1258
|
-
* @returns
|
|
1294
|
+
* @returns `{ wallet_id, address, balances, total_amount_usd }`
|
|
1259
1295
|
*
|
|
1260
1296
|
* @example
|
|
1261
1297
|
* ```typescript
|
|
1262
|
-
* const balances =
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1298
|
+
* const { address, total_amount_usd, balances } =
|
|
1299
|
+
* await client.wallets.getBalances(walletId);
|
|
1300
|
+
* console.log(`${address} → $${total_amount_usd}`);
|
|
1301
|
+
* for (const b of balances) {
|
|
1302
|
+
* console.log(b.asset.id, b.amount_usd);
|
|
1265
1303
|
* }
|
|
1266
1304
|
* ```
|
|
1267
1305
|
*/
|
|
1268
1306
|
async getBalances(walletId) {
|
|
1269
|
-
|
|
1307
|
+
return this.transport.request({
|
|
1270
1308
|
method: "GET",
|
|
1271
1309
|
path: `/wallets/${walletId}/balances`
|
|
1272
1310
|
});
|
|
1273
|
-
return response.balances ? [...response.balances] : [];
|
|
1274
1311
|
}
|
|
1275
1312
|
/**
|
|
1276
|
-
*
|
|
1313
|
+
* Send a transaction from a wallet.
|
|
1314
|
+
*
|
|
1315
|
+
* The platform expects an **endorsed request** envelope —
|
|
1316
|
+
* `{ signatures, intent }` — at this endpoint. Build the
|
|
1317
|
+
* `SendTransactionIntent`, canonicalize it per RFC 8785 (JCS), sign
|
|
1318
|
+
* with the wallet's signer-group ECDSA P-256 key, base64-encode the
|
|
1319
|
+
* DER signature, then post the envelope.
|
|
1277
1320
|
*
|
|
1278
1321
|
* @param walletId - Wallet ID
|
|
1279
|
-
* @param data -
|
|
1322
|
+
* @param data - Endorsed wallet transaction request: `{ signatures, intent }`
|
|
1280
1323
|
* @returns Created transaction
|
|
1281
1324
|
*
|
|
1282
1325
|
* @example
|
|
1283
1326
|
* ```typescript
|
|
1327
|
+
* import canonicalize from 'canonicalize';
|
|
1328
|
+
* import { createSign, createPrivateKey, randomUUID } from 'node:crypto';
|
|
1329
|
+
*
|
|
1330
|
+
* const intent = {
|
|
1331
|
+
* wallet_id: walletId,
|
|
1332
|
+
* caip2: 'eip155:1', // 11155111 for sepolia
|
|
1333
|
+
* operation: {
|
|
1334
|
+
* kind: 'transfer',
|
|
1335
|
+
* from: wallet.address,
|
|
1336
|
+
* to: '0x...',
|
|
1337
|
+
* amount: '100.00',
|
|
1338
|
+
* asset_id: 'USDC',
|
|
1339
|
+
* },
|
|
1340
|
+
* idempotency_key: randomUUID(),
|
|
1341
|
+
* };
|
|
1342
|
+
* const canonical = canonicalize(intent)!;
|
|
1343
|
+
* const sig = createSign('SHA256').update(canonical).sign({
|
|
1344
|
+
* key: createPrivateKey({ key: privateKeyDer, format: 'der', type: 'pkcs8' }),
|
|
1345
|
+
* dsaEncoding: 'der',
|
|
1346
|
+
* });
|
|
1284
1347
|
* const tx = await client.wallets.createTransaction(walletId, {
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
* asset: 'USDC',
|
|
1288
|
-
* network_id: 'ethereum-mainnet',
|
|
1348
|
+
* signatures: [sig.toString('base64')],
|
|
1349
|
+
* intent,
|
|
1289
1350
|
* });
|
|
1290
1351
|
* ```
|
|
1352
|
+
*
|
|
1353
|
+
* @see https://docs.dakota.xyz/documentation/signing-guide
|
|
1291
1354
|
*/
|
|
1292
1355
|
async createTransaction(walletId, data, options) {
|
|
1293
1356
|
return this.transport.request({
|
|
@@ -1842,11 +1905,15 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
1842
1905
|
});
|
|
1843
1906
|
}
|
|
1844
1907
|
/**
|
|
1845
|
-
* Add
|
|
1908
|
+
* Add an existing signer's public key to a group.
|
|
1909
|
+
*
|
|
1910
|
+
* The endpoint takes `{ member_key }` — the base64 PKIX (SPKI) public
|
|
1911
|
+
* key of an existing signer resource — not a fresh signer definition.
|
|
1912
|
+
* Returns the updated group (with the new member included).
|
|
1846
1913
|
*
|
|
1847
1914
|
* @param signerGroupId - Signer group ID
|
|
1848
|
-
* @param data -
|
|
1849
|
-
* @returns
|
|
1915
|
+
* @param data - `{ member_key }` (the signer's base64 PKIX public key)
|
|
1916
|
+
* @returns The updated signer group
|
|
1850
1917
|
*/
|
|
1851
1918
|
async addSigner(signerGroupId, data, options) {
|
|
1852
1919
|
return this.transport.request({
|
|
@@ -1861,11 +1928,14 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
1861
1928
|
*
|
|
1862
1929
|
* @param signerGroupId - Signer group ID
|
|
1863
1930
|
* @param signerId - Signer ID
|
|
1931
|
+
* @param options - Optional request options (e.g. an explicit idempotency
|
|
1932
|
+
* key — the platform requires one on this DELETE)
|
|
1864
1933
|
*/
|
|
1865
|
-
async removeSigner(signerGroupId, signerId) {
|
|
1934
|
+
async removeSigner(signerGroupId, signerId, options) {
|
|
1866
1935
|
await this.transport.request({
|
|
1867
1936
|
method: "DELETE",
|
|
1868
|
-
path: `/signer-groups/${signerGroupId}/signers/${signerId}
|
|
1937
|
+
path: `/signer-groups/${signerGroupId}/signers/${signerId}`,
|
|
1938
|
+
idempotencyKey: options?.idempotencyKey
|
|
1869
1939
|
});
|
|
1870
1940
|
}
|
|
1871
1941
|
/**
|
|
@@ -2562,6 +2632,446 @@ var SelfServeResource = class extends BaseResource {
|
|
|
2562
2632
|
}
|
|
2563
2633
|
};
|
|
2564
2634
|
|
|
2635
|
+
// src/client/resources/payment-agents.ts
|
|
2636
|
+
var PaymentAgentsResource = class extends BaseResource {
|
|
2637
|
+
/**
|
|
2638
|
+
* Create a hosted payment agent.
|
|
2639
|
+
*
|
|
2640
|
+
* @param data - Payment agent creation data (customer_id, name, hosted)
|
|
2641
|
+
* @returns The created payment agent (id, signer_id, signer_public_key, state)
|
|
2642
|
+
*/
|
|
2643
|
+
async create(data, options) {
|
|
2644
|
+
return this.transport.request({
|
|
2645
|
+
method: "POST",
|
|
2646
|
+
path: "/payment-agents",
|
|
2647
|
+
body: data,
|
|
2648
|
+
idempotencyKey: options?.idempotencyKey
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Get a hosted payment agent.
|
|
2653
|
+
*
|
|
2654
|
+
* Returns the agent together with the wallets it can currently spend
|
|
2655
|
+
* from. `wallet_ids` are DERIVED at query time from the agent signer's
|
|
2656
|
+
* live signer-group membership, so they reflect the agent's access
|
|
2657
|
+
* right now — not just at creation time.
|
|
2658
|
+
*
|
|
2659
|
+
* @param paymentAgentId - Payment agent ID
|
|
2660
|
+
*/
|
|
2661
|
+
async get(paymentAgentId) {
|
|
2662
|
+
return this.transport.request({
|
|
2663
|
+
method: "GET",
|
|
2664
|
+
path: `/payment-agents/${paymentAgentId}`
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* Revoke a hosted payment agent.
|
|
2669
|
+
*
|
|
2670
|
+
* The agent can no longer be used, and its signing key is destroyed
|
|
2671
|
+
* in the isolated signer service (best-effort — the revoked state is
|
|
2672
|
+
* authoritative). Idempotent.
|
|
2673
|
+
*
|
|
2674
|
+
* The response's `signer_group_cleanup` names the signer groups the
|
|
2675
|
+
* (now-revoked) agent's signer still belongs to. A revoked signer can't
|
|
2676
|
+
* sign, but its group membership lingers — remove it with
|
|
2677
|
+
* `client.signerGroups.removeSigner(signer_group_id, signer_id)` to
|
|
2678
|
+
* finish de-provisioning.
|
|
2679
|
+
*
|
|
2680
|
+
* @param paymentAgentId - Payment agent ID
|
|
2681
|
+
* @returns The revoked payment agent (state=revoked, signer_group_cleanup?)
|
|
2682
|
+
*/
|
|
2683
|
+
async revoke(paymentAgentId, options) {
|
|
2684
|
+
return this.transport.request({
|
|
2685
|
+
method: "POST",
|
|
2686
|
+
path: `/payment-agents/${paymentAgentId}/revoke`,
|
|
2687
|
+
idempotencyKey: options?.idempotencyKey
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Draft payment proposals from a conversation.
|
|
2692
|
+
*
|
|
2693
|
+
* Pure cognition, no side effects: turn a customer's natural-language
|
|
2694
|
+
* request into reviewable proposals. Stateless — send the whole
|
|
2695
|
+
* conversation so far in `messages` on each call. Prefer
|
|
2696
|
+
* `AgentConversation` for multi-turn chat; use this directly only for
|
|
2697
|
+
* one-shot proposals.
|
|
2698
|
+
*
|
|
2699
|
+
* @param paymentAgentId - Payment agent ID
|
|
2700
|
+
* @param data - Prompt and/or messages
|
|
2701
|
+
* @returns Proposals (at high confidence) and/or a conversational reply
|
|
2702
|
+
*/
|
|
2703
|
+
async createProposals(paymentAgentId, data, options) {
|
|
2704
|
+
return this.transport.request({
|
|
2705
|
+
method: "POST",
|
|
2706
|
+
path: `/payment-agents/${paymentAgentId}/proposals`,
|
|
2707
|
+
body: data,
|
|
2708
|
+
idempotencyKey: options?.idempotencyKey
|
|
2709
|
+
});
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
// src/client/resources/instructions.ts
|
|
2714
|
+
var InstructionsResource = class extends BaseResource {
|
|
2715
|
+
/**
|
|
2716
|
+
* Accept proposals — actuate them into persisted instructions.
|
|
2717
|
+
*
|
|
2718
|
+
* @param data - The payment agent id and the proposals to accept
|
|
2719
|
+
* @returns instruction_ids + the mandates the batch drafted (in full
|
|
2720
|
+
* wire shape; sign the §8 approval immediately)
|
|
2721
|
+
*/
|
|
2722
|
+
async create(data, options) {
|
|
2723
|
+
return this.transport.request({
|
|
2724
|
+
method: "POST",
|
|
2725
|
+
path: "/instructions",
|
|
2726
|
+
body: data,
|
|
2727
|
+
idempotencyKey: options?.idempotencyKey
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
/**
|
|
2731
|
+
* Get an accepted instruction — its action series and the per-action
|
|
2732
|
+
* downstream artifacts actuation produced.
|
|
2733
|
+
*
|
|
2734
|
+
* @param instructionId - Instruction ID
|
|
2735
|
+
*/
|
|
2736
|
+
async get(instructionId) {
|
|
2737
|
+
return this.transport.request({
|
|
2738
|
+
method: "GET",
|
|
2739
|
+
path: `/instructions/${instructionId}`
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
};
|
|
2743
|
+
|
|
2744
|
+
// src/client/resources/mandates.ts
|
|
2745
|
+
var MandatesResource = class extends BaseResource {
|
|
2746
|
+
/**
|
|
2747
|
+
* List mandates (newest first), with the EFFECTIVE status — a pending or
|
|
2748
|
+
* active mandate past its valid_until reads "expired". Filter with
|
|
2749
|
+
* customer_id / signer_id / status; omit them all for the full collection.
|
|
2750
|
+
*
|
|
2751
|
+
* @param params - Optional pagination + filter parameters
|
|
2752
|
+
* @returns Async iterator of mandates
|
|
2753
|
+
*/
|
|
2754
|
+
list(params) {
|
|
2755
|
+
return this.paginate("/mandates", params);
|
|
2756
|
+
}
|
|
2757
|
+
/**
|
|
2758
|
+
* Get a mandate — the signer it binds, its rule exactly as the customer
|
|
2759
|
+
* approves it, validity, and status.
|
|
2760
|
+
*
|
|
2761
|
+
* @param mandateId - Mandate ID
|
|
2762
|
+
*/
|
|
2763
|
+
async get(mandateId) {
|
|
2764
|
+
return this.transport.request({
|
|
2765
|
+
method: "GET",
|
|
2766
|
+
path: `/mandates/${mandateId}`
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* Create a mandate directly.
|
|
2771
|
+
*
|
|
2772
|
+
* Drafts a PENDING mandate from a direct user interaction — no instruction
|
|
2773
|
+
* back-link. Exactly one binding form names the signer the mandate binds:
|
|
2774
|
+
* `payment_agent_id` (hosted convenience — binds that agent's signer and
|
|
2775
|
+
* anchors to the agent's customer), or `signer_id` together with
|
|
2776
|
+
* `customer_id` (any of the client's signers, BYO keys included). The rule
|
|
2777
|
+
* is the one the customer will approve (via `approve`, a recognized signer
|
|
2778
|
+
* other than the bound one, §8).
|
|
2779
|
+
*
|
|
2780
|
+
* @param data - One binding form + rule + optional validity window
|
|
2781
|
+
* @returns The drafted (pending) mandate
|
|
2782
|
+
*/
|
|
2783
|
+
async create(data, options) {
|
|
2784
|
+
return this.transport.request({
|
|
2785
|
+
method: "POST",
|
|
2786
|
+
path: "/mandates",
|
|
2787
|
+
body: data,
|
|
2788
|
+
idempotencyKey: options?.idempotencyKey
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Approve a mandate.
|
|
2793
|
+
*
|
|
2794
|
+
* A recognized signer OTHER than the bound one signs the mandate payload
|
|
2795
|
+
* (see `mandateSignPayload` + `MandateSigner`) to activate it; arms its
|
|
2796
|
+
* scheduled payments.
|
|
2797
|
+
*
|
|
2798
|
+
* @param mandateId - Mandate ID
|
|
2799
|
+
* @param data - Approver public key (base64 PKIX) + base64 ASN.1 signature
|
|
2800
|
+
*/
|
|
2801
|
+
async approve(mandateId, data, options) {
|
|
2802
|
+
return this.transport.request({
|
|
2803
|
+
method: "POST",
|
|
2804
|
+
path: `/mandates/${mandateId}/approve`,
|
|
2805
|
+
body: data,
|
|
2806
|
+
idempotencyKey: options?.idempotencyKey
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Cancel a mandate.
|
|
2811
|
+
*
|
|
2812
|
+
* Revokes a pending or active mandate. The canceller must be a recognized
|
|
2813
|
+
* signer OTHER than the bound one, with a valid signature over the mandate
|
|
2814
|
+
* payload — the bound signer can never mutate its own mandate.
|
|
2815
|
+
*
|
|
2816
|
+
* @param mandateId - Mandate ID
|
|
2817
|
+
* @param data - Signer public key (base64 PKIX) + base64 ASN.1 signature
|
|
2818
|
+
*/
|
|
2819
|
+
async cancel(mandateId, data, options) {
|
|
2820
|
+
return this.transport.request({
|
|
2821
|
+
method: "POST",
|
|
2822
|
+
path: `/mandates/${mandateId}/cancel`,
|
|
2823
|
+
body: data,
|
|
2824
|
+
idempotencyKey: options?.idempotencyKey
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
};
|
|
2828
|
+
|
|
2829
|
+
// src/client/resources/scheduled-payments.ts
|
|
2830
|
+
var ScheduledPaymentsResource = class extends BaseResource {
|
|
2831
|
+
/**
|
|
2832
|
+
* List scheduled payments (oldest due first).
|
|
2833
|
+
*
|
|
2834
|
+
* Narrow the collection with the optional customer_id, signer_id,
|
|
2835
|
+
* wallet_id, mandate_id, and status filters; omit them all for the full
|
|
2836
|
+
* client collection.
|
|
2837
|
+
*
|
|
2838
|
+
* @param params - Optional pagination + filter parameters
|
|
2839
|
+
* @returns Async iterator of scheduled payments
|
|
2840
|
+
*/
|
|
2841
|
+
list(params) {
|
|
2842
|
+
return this.paginate("/scheduled-payments", params);
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* Schedule payments directly — bypass the proposal flow.
|
|
2846
|
+
*
|
|
2847
|
+
* Creates one or more scheduled payments for a signer under an existing
|
|
2848
|
+
* active mandate (coverage is matched at fire time, so no new signature
|
|
2849
|
+
* is needed here). The schedule is explicit `dates` OR `count` ×
|
|
2850
|
+
* `interval_seconds` from `start_at`.
|
|
2851
|
+
*
|
|
2852
|
+
* @param data - Signer + wallet + destination (or address+network_id) + schedule
|
|
2853
|
+
* @returns The rows that were created (one per date)
|
|
2854
|
+
*/
|
|
2855
|
+
async create(data, options) {
|
|
2856
|
+
return this.transport.request({
|
|
2857
|
+
method: "POST",
|
|
2858
|
+
path: "/scheduled-payments",
|
|
2859
|
+
body: data,
|
|
2860
|
+
idempotencyKey: options?.idempotencyKey
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* Cancel one still-scheduled payment.
|
|
2865
|
+
*
|
|
2866
|
+
* Finalizes the row as cancelled. No signature is required — schedule rows
|
|
2867
|
+
* are bookkeeping, not authorization; the signed grant is the MANDATE,
|
|
2868
|
+
* which this does not touch.
|
|
2869
|
+
*
|
|
2870
|
+
* @param scheduledPaymentId - Scheduled payment ID
|
|
2871
|
+
*/
|
|
2872
|
+
async cancel(scheduledPaymentId, options) {
|
|
2873
|
+
await this.transport.request({
|
|
2874
|
+
method: "POST",
|
|
2875
|
+
path: `/scheduled-payments/${scheduledPaymentId}/cancel`,
|
|
2876
|
+
idempotencyKey: options?.idempotencyKey
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2880
|
+
|
|
2881
|
+
// src/client/resources/insights.ts
|
|
2882
|
+
var InsightsResource = class extends BaseResource {
|
|
2883
|
+
/**
|
|
2884
|
+
* Get the customer's account insight report.
|
|
2885
|
+
*
|
|
2886
|
+
* A deterministic, read-only report: a snapshot of typed facts
|
|
2887
|
+
* (funding-wallet balances, upcoming totals, open payments, active
|
|
2888
|
+
* mandates), observations (`insights`), and advisory recommendations
|
|
2889
|
+
* (`suggestions`). Every item carries `evidence` — typed references to
|
|
2890
|
+
* the platform objects it was computed from. `kind` is an OPEN set;
|
|
2891
|
+
* ignore kinds you do not recognize.
|
|
2892
|
+
*
|
|
2893
|
+
* @param customerId - Customer ID
|
|
2894
|
+
* @returns The customer's insight report
|
|
2895
|
+
*/
|
|
2896
|
+
async get(customerId) {
|
|
2897
|
+
return this.transport.request({
|
|
2898
|
+
method: "GET",
|
|
2899
|
+
path: `/customers/${customerId}/insights`
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Ask about the customer's account.
|
|
2904
|
+
*
|
|
2905
|
+
* A read-only, advisory conversation. Stateless: send the conversation so
|
|
2906
|
+
* far in `messages` on each call; the response is the assistant's next
|
|
2907
|
+
* plain-text `reply`. The assistant narrates the same deterministic report
|
|
2908
|
+
* {@link get} returns — it never originates a number, never proposes, and
|
|
2909
|
+
* never moves money. Rate-limited per customer (hourly burst + daily
|
|
2910
|
+
* window) — a 429 means back off and retry later.
|
|
2911
|
+
*
|
|
2912
|
+
* @param customerId - Customer ID
|
|
2913
|
+
* @param data - The conversation so far (1–40 messages)
|
|
2914
|
+
* @returns The assistant's reply (+ how the boundary screen treated the turn)
|
|
2915
|
+
*/
|
|
2916
|
+
async chat(customerId, data, options) {
|
|
2917
|
+
return this.transport.request({
|
|
2918
|
+
method: "POST",
|
|
2919
|
+
path: `/customers/${customerId}/insights/chat`,
|
|
2920
|
+
body: data,
|
|
2921
|
+
idempotencyKey: options?.idempotencyKey
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
};
|
|
2925
|
+
|
|
2926
|
+
// src/agentic/chat.ts
|
|
2927
|
+
var AgentConversation = class {
|
|
2928
|
+
client;
|
|
2929
|
+
paymentAgentId;
|
|
2930
|
+
history = [];
|
|
2931
|
+
constructor(client, paymentAgentId, history) {
|
|
2932
|
+
this.client = client;
|
|
2933
|
+
this.paymentAgentId = paymentAgentId;
|
|
2934
|
+
if (history && history.length > 0) {
|
|
2935
|
+
this.history = history.map(cloneMessage);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* Adds the user's message to the transcript, asks the agent, records the
|
|
2940
|
+
* agent's reply, and returns the turn. When `hasProposals` is true the
|
|
2941
|
+
* agent has drafted a reviewable action series; otherwise `reply` holds
|
|
2942
|
+
* its next question.
|
|
2943
|
+
*
|
|
2944
|
+
* On error the optimistic user turn is rolled back, so the caller may
|
|
2945
|
+
* retry the same call without duplicating it.
|
|
2946
|
+
*/
|
|
2947
|
+
async send(userMessage) {
|
|
2948
|
+
return this.sendWithAttachments(userMessage);
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* {@link send} with documents (e.g. an invoice PDF) attached to the user
|
|
2952
|
+
* turn for the agent to read and draft payments from. Same turn semantics
|
|
2953
|
+
* and rollback-on-error behavior as `send`. Attachments ride only on the
|
|
2954
|
+
* turn they are passed; the stateless transcript keeps the agent's text
|
|
2955
|
+
* reply, so a follow-up turn relies on that summary rather than re-sending
|
|
2956
|
+
* the document.
|
|
2957
|
+
*/
|
|
2958
|
+
async sendWithAttachments(userMessage, attachments) {
|
|
2959
|
+
const hasAttachments = attachments !== void 0 && attachments.length > 0;
|
|
2960
|
+
this.history.push({
|
|
2961
|
+
role: "user",
|
|
2962
|
+
content: userMessage,
|
|
2963
|
+
...hasAttachments ? { attachments } : {}
|
|
2964
|
+
});
|
|
2965
|
+
const messages = this.history.map(serializeMessage);
|
|
2966
|
+
if (hasAttachments) {
|
|
2967
|
+
const last = this.history[this.history.length - 1];
|
|
2968
|
+
if (last) {
|
|
2969
|
+
delete last.attachments;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
let result;
|
|
2973
|
+
try {
|
|
2974
|
+
result = await this.client.paymentAgents.createProposals(this.paymentAgentId, {
|
|
2975
|
+
messages
|
|
2976
|
+
});
|
|
2977
|
+
} catch (err) {
|
|
2978
|
+
this.history.pop();
|
|
2979
|
+
throw err;
|
|
2980
|
+
}
|
|
2981
|
+
const turn = {
|
|
2982
|
+
reply: result.reply ?? "",
|
|
2983
|
+
proposals: result.proposals ? [...result.proposals] : [],
|
|
2984
|
+
hasProposals: !!result.proposals && result.proposals.length > 0,
|
|
2985
|
+
conversationStatus: result.conversation_status ?? ""
|
|
2986
|
+
};
|
|
2987
|
+
let assistant = turn.reply;
|
|
2988
|
+
if (!assistant) {
|
|
2989
|
+
assistant = turn.hasProposals ? "(drafted proposals for your review)" : "(no reply)";
|
|
2990
|
+
}
|
|
2991
|
+
this.history.push({ role: "assistant", content: assistant });
|
|
2992
|
+
return turn;
|
|
2993
|
+
}
|
|
2994
|
+
/**
|
|
2995
|
+
* A copy of the full transcript so far. Persist this between requests in
|
|
2996
|
+
* a stateless backend and rebuild with
|
|
2997
|
+
* {@link DakotaClient.resumeAgentConversation}.
|
|
2998
|
+
*/
|
|
2999
|
+
messages() {
|
|
3000
|
+
return this.history.map(cloneMessage);
|
|
3001
|
+
}
|
|
3002
|
+
};
|
|
3003
|
+
function cloneMessage(m) {
|
|
3004
|
+
const out = { role: m.role, content: m.content };
|
|
3005
|
+
if (m.attachments && m.attachments.length > 0) {
|
|
3006
|
+
out.attachments = m.attachments.map((a) => ({ ...a }));
|
|
3007
|
+
}
|
|
3008
|
+
return out;
|
|
3009
|
+
}
|
|
3010
|
+
function serializeMessage(m) {
|
|
3011
|
+
const out = { role: m.role, content: m.content };
|
|
3012
|
+
if (m.attachments && m.attachments.length > 0) {
|
|
3013
|
+
out.attachments = m.attachments.map((a) => {
|
|
3014
|
+
const document = {
|
|
3015
|
+
media_type: a.mediaType,
|
|
3016
|
+
data: Buffer.from(a.data).toString("base64")
|
|
3017
|
+
};
|
|
3018
|
+
if (a.filename) {
|
|
3019
|
+
document.filename = a.filename;
|
|
3020
|
+
}
|
|
3021
|
+
return { type: "document", document };
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
return out;
|
|
3025
|
+
}
|
|
3026
|
+
async function attachUserToWallet(client, walletId, signerPublicKey, spendingGroupId, options) {
|
|
3027
|
+
if (!walletId || !signerPublicKey || !spendingGroupId) {
|
|
3028
|
+
throw new Error("walletId, signerPublicKey and spendingGroupId are all required");
|
|
3029
|
+
}
|
|
3030
|
+
await requireGroupOnWallet(client, walletId, spendingGroupId);
|
|
3031
|
+
const group = await client.signerGroups.get(spendingGroupId);
|
|
3032
|
+
for (const member of group.members ?? []) {
|
|
3033
|
+
if (member.public_key === signerPublicKey) {
|
|
3034
|
+
return { alreadyMember: true };
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
await client.signerGroups.addSigner(
|
|
3038
|
+
spendingGroupId,
|
|
3039
|
+
{ member_key: signerPublicKey },
|
|
3040
|
+
{ idempotencyKey: options?.idempotencyKey ?? randomUUID() }
|
|
3041
|
+
);
|
|
3042
|
+
return { alreadyMember: false };
|
|
3043
|
+
}
|
|
3044
|
+
async function detachUserFromWallet(client, walletId, signerPublicKey, spendingGroupId, options) {
|
|
3045
|
+
if (!walletId || !signerPublicKey || !spendingGroupId) {
|
|
3046
|
+
throw new Error("walletId, signerPublicKey and spendingGroupId are all required");
|
|
3047
|
+
}
|
|
3048
|
+
await requireGroupOnWallet(client, walletId, spendingGroupId);
|
|
3049
|
+
const group = await client.signerGroups.get(spendingGroupId);
|
|
3050
|
+
let signerId = "";
|
|
3051
|
+
for (const member of group.members ?? []) {
|
|
3052
|
+
if (member.public_key === signerPublicKey) {
|
|
3053
|
+
signerId = member.id ?? "";
|
|
3054
|
+
break;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
if (!signerId) {
|
|
3058
|
+
return { wasMember: false };
|
|
3059
|
+
}
|
|
3060
|
+
await client.signerGroups.removeSigner(spendingGroupId, signerId, {
|
|
3061
|
+
idempotencyKey: options?.idempotencyKey ?? randomUUID()
|
|
3062
|
+
});
|
|
3063
|
+
return { wasMember: true };
|
|
3064
|
+
}
|
|
3065
|
+
async function requireGroupOnWallet(client, walletId, spendingGroupId) {
|
|
3066
|
+
const wallets = await client.signerGroups.getWallets(spendingGroupId);
|
|
3067
|
+
for (const w of wallets) {
|
|
3068
|
+
if (w.id === walletId) {
|
|
3069
|
+
return;
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
throw new Error(`signer group ${spendingGroupId} is not attached to wallet ${walletId}`);
|
|
3073
|
+
}
|
|
3074
|
+
|
|
2565
3075
|
// src/client/client.ts
|
|
2566
3076
|
var DakotaClient = class {
|
|
2567
3077
|
config;
|
|
@@ -2603,6 +3113,16 @@ var DakotaClient = class {
|
|
|
2603
3113
|
sandbox;
|
|
2604
3114
|
/** Self-Serve Credits API - manage prepaid transfer credits */
|
|
2605
3115
|
selfServe;
|
|
3116
|
+
/** Payment Agents API (ALPHA) - hosted signing agents that draft payments */
|
|
3117
|
+
paymentAgents;
|
|
3118
|
+
/** Instructions API (ALPHA) - accept and inspect actuated proposals */
|
|
3119
|
+
instructions;
|
|
3120
|
+
/** Mandates API (ALPHA) - the §8 authorizations that arm scheduled payments */
|
|
3121
|
+
mandates;
|
|
3122
|
+
/** Scheduled Payments API (ALPHA) - schedule rows created from instructions */
|
|
3123
|
+
scheduledPayments;
|
|
3124
|
+
/** Insights API (ALPHA) - read-only advisory reporting over agentic activity */
|
|
3125
|
+
insights;
|
|
2606
3126
|
/**
|
|
2607
3127
|
* Create a new Dakota client.
|
|
2608
3128
|
*
|
|
@@ -2656,6 +3176,53 @@ var DakotaClient = class {
|
|
|
2656
3176
|
this.info = new InfoResource(this.transport);
|
|
2657
3177
|
this.sandbox = new SandboxResource(this.transport);
|
|
2658
3178
|
this.selfServe = new SelfServeResource(this.transport);
|
|
3179
|
+
this.paymentAgents = new PaymentAgentsResource(this.transport);
|
|
3180
|
+
this.instructions = new InstructionsResource(this.transport);
|
|
3181
|
+
this.mandates = new MandatesResource(this.transport);
|
|
3182
|
+
this.scheduledPayments = new ScheduledPaymentsResource(this.transport);
|
|
3183
|
+
this.insights = new InsightsResource(this.transport);
|
|
3184
|
+
}
|
|
3185
|
+
// ==========================================================================
|
|
3186
|
+
// Agentic Payments high-level helpers (ALPHA)
|
|
3187
|
+
//
|
|
3188
|
+
// Collapse the multi-step, crypto-heavy hosted-agent flows into single
|
|
3189
|
+
// calls with good defaults. The raw operations remain reachable via
|
|
3190
|
+
// `signerGroups.addSigner` / `signerGroups.removeSigner` and friends.
|
|
3191
|
+
// ==========================================================================
|
|
3192
|
+
/**
|
|
3193
|
+
* Start a fresh multi-turn conversation with a payment agent.
|
|
3194
|
+
*
|
|
3195
|
+
* @see AgentConversation
|
|
3196
|
+
*/
|
|
3197
|
+
newAgentConversation(paymentAgentId) {
|
|
3198
|
+
return new AgentConversation(this, paymentAgentId);
|
|
3199
|
+
}
|
|
3200
|
+
/**
|
|
3201
|
+
* Rebuild a conversation from a persisted transcript (oldest first) —
|
|
3202
|
+
* for backends that store the history between requests.
|
|
3203
|
+
*/
|
|
3204
|
+
resumeAgentConversation(paymentAgentId, history) {
|
|
3205
|
+
return new AgentConversation(this, paymentAgentId, history);
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Grant a principal (user or agent — both are just signers) permission to
|
|
3209
|
+
* spend from a wallet by adding its signer to an EXISTING signer group on
|
|
3210
|
+
* that wallet. Idempotent; errors if the group isn't attached to the wallet.
|
|
3211
|
+
*
|
|
3212
|
+
* @see attachUserToWallet in `agentic/wallets.ts` for the full contract.
|
|
3213
|
+
*/
|
|
3214
|
+
attachUserToWallet(walletId, signerPublicKey, spendingGroupId, options) {
|
|
3215
|
+
return attachUserToWallet(this, walletId, signerPublicKey, spendingGroupId, options);
|
|
3216
|
+
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Revoke a principal's spend permission by removing its signer from the
|
|
3219
|
+
* given signer group — the inverse of {@link attachUserToWallet}.
|
|
3220
|
+
* Idempotent; errors if the group isn't attached to the wallet.
|
|
3221
|
+
*
|
|
3222
|
+
* @see detachUserFromWallet in `agentic/wallets.ts` for the full contract.
|
|
3223
|
+
*/
|
|
3224
|
+
detachUserFromWallet(walletId, signerPublicKey, spendingGroupId, options) {
|
|
3225
|
+
return detachUserFromWallet(this, walletId, signerPublicKey, spendingGroupId, options);
|
|
2659
3226
|
}
|
|
2660
3227
|
/**
|
|
2661
3228
|
* Get the resolved base URL.
|
|
@@ -2665,6 +3232,228 @@ var DakotaClient = class {
|
|
|
2665
3232
|
}
|
|
2666
3233
|
};
|
|
2667
3234
|
|
|
2668
|
-
|
|
3235
|
+
// src/agentic/canonicalize.ts
|
|
3236
|
+
function canonicalJSON(value) {
|
|
3237
|
+
return canonicalize(value);
|
|
3238
|
+
}
|
|
3239
|
+
function canonicalize(value) {
|
|
3240
|
+
if (value === null || value === void 0) {
|
|
3241
|
+
return "null";
|
|
3242
|
+
}
|
|
3243
|
+
if (typeof value === "boolean") {
|
|
3244
|
+
return value ? "true" : "false";
|
|
3245
|
+
}
|
|
3246
|
+
if (typeof value === "number") {
|
|
3247
|
+
if (!Number.isFinite(value)) {
|
|
3248
|
+
throw new TypeError(`canonical JSON: non-finite number ${value}`);
|
|
3249
|
+
}
|
|
3250
|
+
return JSON.stringify(value);
|
|
3251
|
+
}
|
|
3252
|
+
if (typeof value === "string") {
|
|
3253
|
+
return JSON.stringify(value);
|
|
3254
|
+
}
|
|
3255
|
+
if (typeof value === "bigint") {
|
|
3256
|
+
throw new TypeError("canonical JSON: bigint values are not supported");
|
|
3257
|
+
}
|
|
3258
|
+
if (Array.isArray(value)) {
|
|
3259
|
+
const parts = value.map((item) => canonicalize(item));
|
|
3260
|
+
return `[${parts.join(",")}]`;
|
|
3261
|
+
}
|
|
3262
|
+
if (typeof value === "object") {
|
|
3263
|
+
const obj = value;
|
|
3264
|
+
const keys = Object.keys(obj).sort();
|
|
3265
|
+
const parts = keys.map((key) => `${JSON.stringify(key)}:${canonicalize(obj[key])}`);
|
|
3266
|
+
return `{${parts.join(",")}}`;
|
|
3267
|
+
}
|
|
3268
|
+
throw new TypeError(`canonical JSON: unsupported value type ${typeof value}`);
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// src/agentic/sign.ts
|
|
3272
|
+
function mandateSignPayload(mandate, action) {
|
|
3273
|
+
if (!mandate.id) {
|
|
3274
|
+
throw new Error("mandate has no id");
|
|
3275
|
+
}
|
|
3276
|
+
if (!mandate.bound_signer_id) {
|
|
3277
|
+
throw new Error("mandate has no bound_signer_id");
|
|
3278
|
+
}
|
|
3279
|
+
if (!mandate.rule) {
|
|
3280
|
+
throw new Error("mandate has no rule");
|
|
3281
|
+
}
|
|
3282
|
+
const encoded = canonicalJSON({
|
|
3283
|
+
action,
|
|
3284
|
+
id: mandate.id,
|
|
3285
|
+
bound_signer: mandate.bound_signer_id,
|
|
3286
|
+
rule: mandate.rule,
|
|
3287
|
+
valid_from: mandate.valid_from ?? 0,
|
|
3288
|
+
valid_until: mandate.valid_until ?? 0
|
|
3289
|
+
});
|
|
3290
|
+
return new TextEncoder().encode(encoded);
|
|
3291
|
+
}
|
|
3292
|
+
function attachGroupPayload(walletId, groupId, idempotencyKey) {
|
|
3293
|
+
return textBytes(
|
|
3294
|
+
canonicalJSON({
|
|
3295
|
+
type: "attach_group_to_wallet",
|
|
3296
|
+
wallet_id: walletId,
|
|
3297
|
+
group_id: groupId,
|
|
3298
|
+
idempotency_key: idempotencyKey
|
|
3299
|
+
})
|
|
3300
|
+
);
|
|
3301
|
+
}
|
|
3302
|
+
function attachPolicyPayload(walletId, policyId, idempotencyKey) {
|
|
3303
|
+
return textBytes(
|
|
3304
|
+
canonicalJSON({
|
|
3305
|
+
type: "attach_policy_to_wallet",
|
|
3306
|
+
wallet_id: walletId,
|
|
3307
|
+
policy_id: policyId,
|
|
3308
|
+
idempotency_key: idempotencyKey
|
|
3309
|
+
})
|
|
3310
|
+
);
|
|
3311
|
+
}
|
|
3312
|
+
function detachGroupPayload(walletId, groupId, idempotencyKey) {
|
|
3313
|
+
return textBytes(
|
|
3314
|
+
canonicalJSON({
|
|
3315
|
+
type: "detach_group_from_wallet",
|
|
3316
|
+
wallet_id: walletId,
|
|
3317
|
+
group_id: groupId,
|
|
3318
|
+
idempotency_key: idempotencyKey
|
|
3319
|
+
})
|
|
3320
|
+
);
|
|
3321
|
+
}
|
|
3322
|
+
function detachPolicyPayload(walletId, policyId, idempotencyKey) {
|
|
3323
|
+
return textBytes(
|
|
3324
|
+
canonicalJSON({
|
|
3325
|
+
type: "detach_policy_from_wallet",
|
|
3326
|
+
wallet_id: walletId,
|
|
3327
|
+
policy_id: policyId,
|
|
3328
|
+
idempotency_key: idempotencyKey
|
|
3329
|
+
})
|
|
3330
|
+
);
|
|
3331
|
+
}
|
|
3332
|
+
function deletePolicyPayload(policyId, idempotencyKey) {
|
|
3333
|
+
return textBytes(
|
|
3334
|
+
canonicalJSON({
|
|
3335
|
+
type: "delete_policy",
|
|
3336
|
+
policy_id: policyId,
|
|
3337
|
+
idempotency_key: idempotencyKey
|
|
3338
|
+
})
|
|
3339
|
+
);
|
|
3340
|
+
}
|
|
3341
|
+
function removePolicyRulePayload(policyId, ruleId, idempotencyKey) {
|
|
3342
|
+
return textBytes(
|
|
3343
|
+
canonicalJSON({
|
|
3344
|
+
type: "remove_policy_rule",
|
|
3345
|
+
policy_id: policyId,
|
|
3346
|
+
rule_id: ruleId,
|
|
3347
|
+
idempotency_key: idempotencyKey
|
|
3348
|
+
})
|
|
3349
|
+
);
|
|
3350
|
+
}
|
|
3351
|
+
function updatePolicyRulePayload(policyId, ruleId, updatedDefinition, idempotencyKey) {
|
|
3352
|
+
return textBytes(
|
|
3353
|
+
canonicalJSON({
|
|
3354
|
+
type: "update_policy_rule",
|
|
3355
|
+
policy_id: policyId,
|
|
3356
|
+
rule_id: ruleId,
|
|
3357
|
+
updated_definition: updatedDefinition,
|
|
3358
|
+
idempotency_key: idempotencyKey
|
|
3359
|
+
})
|
|
3360
|
+
);
|
|
3361
|
+
}
|
|
3362
|
+
function addPolicyRulePayload(policyId, action, ruleType, definition, idempotencyKey) {
|
|
3363
|
+
return textBytes(
|
|
3364
|
+
canonicalJSON({
|
|
3365
|
+
type: "add_policy_rule",
|
|
3366
|
+
action,
|
|
3367
|
+
rule_type: ruleType,
|
|
3368
|
+
policy_id: policyId,
|
|
3369
|
+
definition,
|
|
3370
|
+
idempotency_key: idempotencyKey
|
|
3371
|
+
})
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
3374
|
+
function textBytes(s) {
|
|
3375
|
+
return new TextEncoder().encode(s);
|
|
3376
|
+
}
|
|
3377
|
+
var P256MandateSigner = class _P256MandateSigner {
|
|
3378
|
+
privateKey;
|
|
3379
|
+
publicKey;
|
|
3380
|
+
constructor(privateKey, publicKey) {
|
|
3381
|
+
this.privateKey = privateKey;
|
|
3382
|
+
this.publicKey = publicKey;
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* Generate a fresh P-256 keypair.
|
|
3386
|
+
*/
|
|
3387
|
+
static generate() {
|
|
3388
|
+
const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
3389
|
+
return new _P256MandateSigner(privateKey, publicKey);
|
|
3390
|
+
}
|
|
3391
|
+
/**
|
|
3392
|
+
* Adopt an existing P-256 private key. Accepts a PKCS#8 PEM string, a
|
|
3393
|
+
* DER-encoded PKCS#8 buffer, or a Node {@link KeyObject}.
|
|
3394
|
+
*/
|
|
3395
|
+
static fromPrivateKey(key) {
|
|
3396
|
+
const privateKey = typeof key === "string" || key instanceof Uint8Array ? createPrivateKey({
|
|
3397
|
+
key,
|
|
3398
|
+
format: typeof key === "string" ? "pem" : "der",
|
|
3399
|
+
type: "pkcs8"
|
|
3400
|
+
}) : key;
|
|
3401
|
+
if (privateKey.asymmetricKeyType !== "ec") {
|
|
3402
|
+
throw new Error("a P-256 private key is required (ES256)");
|
|
3403
|
+
}
|
|
3404
|
+
const details = privateKey.asymmetricKeyDetails;
|
|
3405
|
+
if (details?.namedCurve !== "prime256v1") {
|
|
3406
|
+
throw new Error("a P-256 private key is required (ES256)");
|
|
3407
|
+
}
|
|
3408
|
+
const publicKey = createPublicKey(privateKey);
|
|
3409
|
+
return new _P256MandateSigner(privateKey, publicKey);
|
|
3410
|
+
}
|
|
3411
|
+
/**
|
|
3412
|
+
* base64 PKIX (SPKI) public key — pass this as the signer's registered
|
|
3413
|
+
* public key at agent creation / mandate approval.
|
|
3414
|
+
*/
|
|
3415
|
+
publicKeyBase64() {
|
|
3416
|
+
const der = this.publicKey.export({ format: "der", type: "spki" });
|
|
3417
|
+
return Buffer.from(der).toString("base64");
|
|
3418
|
+
}
|
|
3419
|
+
/**
|
|
3420
|
+
* Returns base64( ASN.1 ECDSA signature over SHA-256(payload) ).
|
|
3421
|
+
*/
|
|
3422
|
+
sign(payload) {
|
|
3423
|
+
const signer = createSign("SHA256");
|
|
3424
|
+
signer.update(payload);
|
|
3425
|
+
const sig = signer.sign({ key: this.privateKey, dsaEncoding: "der" });
|
|
3426
|
+
return Buffer.from(sig).toString("base64");
|
|
3427
|
+
}
|
|
3428
|
+
};
|
|
3429
|
+
function verifyMandateSignature(publicKeyBase64, payload, signatureBase64) {
|
|
3430
|
+
let publicKey;
|
|
3431
|
+
try {
|
|
3432
|
+
publicKey = createPublicKey({
|
|
3433
|
+
key: Buffer.from(publicKeyBase64, "base64"),
|
|
3434
|
+
format: "der",
|
|
3435
|
+
type: "spki"
|
|
3436
|
+
});
|
|
3437
|
+
} catch (err) {
|
|
3438
|
+
throw new Error(`parse public key: ${err.message}`);
|
|
3439
|
+
}
|
|
3440
|
+
if (publicKey.asymmetricKeyType !== "ec") {
|
|
3441
|
+
throw new Error("not a P-256 public key (ES256 requires P-256)");
|
|
3442
|
+
}
|
|
3443
|
+
if (publicKey.asymmetricKeyDetails?.namedCurve !== "prime256v1") {
|
|
3444
|
+
throw new Error("not a P-256 public key (ES256 requires P-256)");
|
|
3445
|
+
}
|
|
3446
|
+
const verifier = createVerify("SHA256");
|
|
3447
|
+
verifier.update(payload);
|
|
3448
|
+
const ok = verifier.verify(
|
|
3449
|
+
{ key: publicKey, dsaEncoding: "der" },
|
|
3450
|
+
Buffer.from(signatureBase64, "base64")
|
|
3451
|
+
);
|
|
3452
|
+
if (!ok) {
|
|
3453
|
+
throw new Error("signature verification failed");
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
export { APIError, AccountsResource, AgentConversation, ApiKeysResource, ApplicationsResource, AuthMode, AutoTransactionsResource, ConfigurationError, CustomersResource, DEFAULT_RETRY_POLICY, DakotaClient, DestinationsResource, Environment, EventsResource, InfoResource, InsightsResource, InstructionsResource, MandatesResource, P256MandateSigner, PaginatedIterator, PaymentAgentsResource, PoliciesResource, RecipientsResource, SandboxResource, ScheduledPaymentsResource, SelfServeResource, SignerGroupsResource, SignersResource, TransactionsResource, TransportError, UsersResource, WalletsResource, WebhooksResource, addPolicyRulePayload, attachGroupPayload, attachPolicyPayload, attachUserToWallet, canonicalJSON, consoleLogger, deletePolicyPayload, detachGroupPayload, detachPolicyPayload, detachUserFromWallet, getEnvironmentURL, mandateSignPayload, noopLogger, paginate, removePolicyRulePayload, updatePolicyRulePayload, verifyMandateSignature };
|
|
2669
3458
|
//# sourceMappingURL=index.mjs.map
|
|
2670
3459
|
//# sourceMappingURL=index.mjs.map
|