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