@dakota-xyz/ts-sdk 1.6.0 → 2.1.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/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) {
@@ -676,12 +678,87 @@ var CustomersResource = class extends BaseResource {
676
678
  path: `/customers/${customerId}`
677
679
  });
678
680
  }
681
+ /**
682
+ * Delete a customer record.
683
+ *
684
+ * Soft-deletes the customer. Blocked with a 409 if the customer still has
685
+ * associated accounts, or is referenced as a sub-client by another customer.
686
+ *
687
+ * @param customerId - Customer ID (KSUID)
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * await client.customers.delete('cust_abc123');
692
+ * ```
693
+ */
694
+ async delete(customerId) {
695
+ await this.transport.request({
696
+ method: "DELETE",
697
+ path: `/customers/${customerId}`
698
+ });
699
+ }
700
+ /**
701
+ * List a customer's capabilities and what is still needed to unlock each.
702
+ *
703
+ * Returns the customer's rails (e.g. `international_wire`) with a status and
704
+ * the OUTSTANDING requirements — terms to accept, documents to upload — that
705
+ * gate them. Partner-agnostic: requirements are keyed by an opaque terms id
706
+ * or document type, never a provider or partner name.
707
+ *
708
+ * @param customerId - Customer ID (KSUID)
709
+ * @returns The customer's capabilities and their outstanding requirements
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * const { capabilities } = await client.customers.getCapabilities(customerId);
714
+ * for (const cap of capabilities) {
715
+ * if (cap.status !== 'action_required') continue;
716
+ * for (const req of cap.requirements) {
717
+ * console.log(`${cap.capability}: ${req.title} → ${req.url}`);
718
+ * }
719
+ * }
720
+ * ```
721
+ */
722
+ async getCapabilities(customerId) {
723
+ return this.transport.request({
724
+ method: "GET",
725
+ path: `/customers/${customerId}/capabilities`
726
+ });
727
+ }
728
+ /**
729
+ * Mint a fresh application link for re-engaging an APPROVED customer.
730
+ *
731
+ * Issues a new onboarding token for an existing approved customer's
732
+ * application and returns the rebuilt `application_url` — use it when the
733
+ * original token has expired and the customer needs to come back through
734
+ * the hosted flow (e.g. to accept outstanding partner disclosures).
735
+ *
736
+ * @param customerId - Customer ID (KSUID)
737
+ * @param options - Request options (e.g., custom idempotency key)
738
+ * @returns The rebuilt application URL
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * const { application_url } = await client.customers.reEngage(customerId);
743
+ * ```
744
+ */
745
+ async reEngage(customerId, options) {
746
+ return this.transport.request({
747
+ method: "POST",
748
+ path: `/customers/${customerId}/re-engagement`,
749
+ idempotencyKey: options?.idempotencyKey
750
+ });
751
+ }
679
752
  /**
680
753
  * Update the sub-client association for a customer.
681
754
  *
682
755
  * Associates or disassociates a customer with a sub-client.
683
756
  * Set `sub_client_id` to associate, or set it to `null` to disassociate.
684
757
  *
758
+ * @deprecated The sub-client association can only be set when a customer is
759
+ * created (`is_sub_client` / `sub_client_id` on `create`) and can no longer
760
+ * be changed afterwards — this endpoint now returns 400.
761
+ *
685
762
  * @param customerId - Customer ID (KSUID)
686
763
  * @param data - Sub-client association data
687
764
  * @param options - Request options (e.g., custom idempotency key)
@@ -758,6 +835,93 @@ var CustomersResource = class extends BaseResource {
758
835
  idempotencyKey: options?.idempotencyKey
759
836
  });
760
837
  }
838
+ /**
839
+ * Import customers from Persona Connect share tokens (`cnst_...`).
840
+ *
841
+ * Unlike the Sumsub import, Persona redemption is asynchronous on Persona's
842
+ * side, so this returns a JOB immediately (HTTP 202). Poll
843
+ * `getPersonaImportJob` for per-token results. Up to 5,000 tokens per
844
+ * request — split larger migrations into multiple batches.
845
+ *
846
+ * Tokens are validated and de-duplicated up front, and a skipped token
847
+ * never blocks an accepted one. A `skipped` entry is about the token STRING
848
+ * (malformed, duplicated in the batch, or already imported) — it is never a
849
+ * compliance decision about a person or application.
850
+ *
851
+ * @param data - The share tokens to import
852
+ * @param options - Request options (e.g., custom idempotency key)
853
+ * @returns The queued job, with any tokens that could not be enqueued
854
+ *
855
+ * @example
856
+ * ```typescript
857
+ * const job = await client.customers.importPersonaTokens({
858
+ * tokens: ['cnst_ABC123def456', 'cnst_GHI789jkl012'],
859
+ * });
860
+ * console.log(`${job.accepted}/${job.total} queued as ${job.job_id}`);
861
+ * ```
862
+ */
863
+ async importPersonaTokens(data, options) {
864
+ return this.transport.request({
865
+ method: "POST",
866
+ path: "/customers/import-persona-tokens",
867
+ body: data,
868
+ idempotencyKey: options?.idempotencyKey
869
+ });
870
+ }
871
+ /**
872
+ * List this client's Persona share-token import jobs, newest first.
873
+ *
874
+ * This endpoint pages on its own cursor (`starting_after` + `has_more`), not
875
+ * the standard list envelope, so it returns a single page rather than an
876
+ * async iterator.
877
+ *
878
+ * @param params - Optional `limit` and `starting_after` job-id cursor
879
+ * @returns One page of job summaries plus a `has_more` flag
880
+ *
881
+ * @example
882
+ * ```typescript
883
+ * const { jobs, has_more } = await client.customers.listPersonaImportJobs({ limit: 20 });
884
+ * ```
885
+ */
886
+ async listPersonaImportJobs(params) {
887
+ return this.transport.request({
888
+ method: "GET",
889
+ path: "/customers/persona-import-jobs",
890
+ query: { ...params }
891
+ });
892
+ }
893
+ /**
894
+ * Get a Persona import job's status and its per-token results.
895
+ *
896
+ * Result rows page on a row-index cursor: pass the last row's `index` as
897
+ * `results_after_index` while `has_more_results` is true.
898
+ *
899
+ * @param jobId - Import job ID (`pij_...`)
900
+ * @param params - Optional `results_limit` (1-500) and `results_after_index`
901
+ * @returns Job status, row counts, and one page of result rows
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * let after: number | undefined;
906
+ * do {
907
+ * const job = await client.customers.getPersonaImportJob(jobId, {
908
+ * results_after_index: after,
909
+ * });
910
+ * for (const row of job.results ?? []) {
911
+ * if (row.state === 'failed') console.error(row.token, row.error);
912
+ * after = row.index;
913
+ * }
914
+ * if (!job.has_more_results) break;
915
+ * } while (true);
916
+ * ```
917
+ */
918
+ async getPersonaImportJob(jobId, params) {
919
+ return this.transport.request({
920
+ method: "GET",
921
+ path: `/customers/persona-import-jobs/${jobId}`,
922
+ query: { ...params }
923
+ });
924
+ }
761
925
  };
762
926
 
763
927
  // src/client/resources/recipients.ts
@@ -1522,8 +1686,18 @@ var ApplicationsResource = class extends BaseResource {
1522
1686
  /**
1523
1687
  * Submit an attestation for an application.
1524
1688
  *
1689
+ * Additionally supplying `disclosure_id` (a terms key the provider
1690
+ * declared, e.g. `partner_disclosures`) and `disclosure_version` records the
1691
+ * attestation as a PARTNER DISCLOSURE acknowledgment instead of a standard
1692
+ * onboarding one: acceptance is stamped `customer_online`, the
1693
+ * partner-onboarding substatus advances, and an already-approved
1694
+ * application is reprovisioned. The API stays partner-agnostic — callers
1695
+ * supply a terms key and version, never a partner name. Get the outstanding
1696
+ * ones from `customers.getCapabilities(customerId)`.
1697
+ *
1525
1698
  * @param applicationId - Application ID
1526
- * @param data - Attestation data (type, timestamp, applicant_id)
1699
+ * @param data - Attestation data (type, timestamp, applicant_id), plus
1700
+ * `disclosure_id` + `disclosure_version` to accept a partner disclosure
1527
1701
  */
1528
1702
  async submitAttestation(applicationId, data, options) {
1529
1703
  await this.transport.request({
@@ -1895,21 +2069,39 @@ var SignerGroupsResource = class extends BaseResource {
1895
2069
  /**
1896
2070
  * Get a signer group by ID.
1897
2071
  *
2072
+ * Pass `{ include_removed: true }` to also get a `removed_members` array of
2073
+ * signers that were removed from this group, each carrying its `removed_at`
2074
+ * timestamp. Defaults to active members only.
2075
+ *
1898
2076
  * @param signerGroupId - Signer group ID
2077
+ * @param params - Optional `{ include_removed }`
1899
2078
  * @returns Signer group record
2079
+ *
2080
+ * @example
2081
+ * ```typescript
2082
+ * const group = await client.signerGroups.get(groupId, { include_removed: true });
2083
+ * for (const s of group.removed_members ?? []) {
2084
+ * console.log(s.name, 'removed at', s.removed_at);
2085
+ * }
2086
+ * ```
1900
2087
  */
1901
- async get(signerGroupId) {
2088
+ async get(signerGroupId, params) {
1902
2089
  return this.transport.request({
1903
2090
  method: "GET",
1904
- path: `/signer-groups/${signerGroupId}`
2091
+ path: `/signer-groups/${signerGroupId}`,
2092
+ query: { ...params }
1905
2093
  });
1906
2094
  }
1907
2095
  /**
1908
- * Add a signer to a group.
2096
+ * Add an existing signer's public key to a group.
2097
+ *
2098
+ * The endpoint takes `{ member_key }` — the base64 PKIX (SPKI) public
2099
+ * key of an existing signer resource — not a fresh signer definition.
2100
+ * Returns the updated group (with the new member included).
1909
2101
  *
1910
2102
  * @param signerGroupId - Signer group ID
1911
- * @param data - Signer creation data
1912
- * @returns Created signer
2103
+ * @param data - `{ member_key }` (the signer's base64 PKIX public key)
2104
+ * @returns The updated signer group
1913
2105
  */
1914
2106
  async addSigner(signerGroupId, data, options) {
1915
2107
  return this.transport.request({
@@ -1923,12 +2115,16 @@ var SignerGroupsResource = class extends BaseResource {
1923
2115
  * Remove a signer from a group.
1924
2116
  *
1925
2117
  * @param signerGroupId - Signer group ID
1926
- * @param signerId - Signer ID
2118
+ * @param signerId - The signer's KSUID `signer_id` — NOT its public key.
2119
+ * (The standalone `client.signers.delete()` takes the public key instead.)
2120
+ * @param options - Optional request options (e.g. an explicit idempotency
2121
+ * key — the platform requires one on this DELETE)
1927
2122
  */
1928
- async removeSigner(signerGroupId, signerId) {
2123
+ async removeSigner(signerGroupId, signerId, options) {
1929
2124
  await this.transport.request({
1930
2125
  method: "DELETE",
1931
- path: `/signer-groups/${signerGroupId}/signers/${signerId}`
2126
+ path: `/signer-groups/${signerGroupId}/signers/${signerId}`,
2127
+ idempotencyKey: options?.idempotencyKey
1932
2128
  });
1933
2129
  }
1934
2130
  /**
@@ -2625,6 +2821,650 @@ var SelfServeResource = class extends BaseResource {
2625
2821
  }
2626
2822
  };
2627
2823
 
2824
+ // src/client/resources/fee-payout-destination.ts
2825
+ var FeePayoutDestinationResource = class extends BaseResource {
2826
+ /**
2827
+ * Get the destination registered to receive your developer-fee payouts.
2828
+ *
2829
+ * @returns The registered destination
2830
+ *
2831
+ * @example
2832
+ * ```typescript
2833
+ * const dest = await client.feePayoutDestination.get();
2834
+ * console.log(dest.chain, dest.wallet_address);
2835
+ * ```
2836
+ */
2837
+ async get() {
2838
+ return this.transport.request({
2839
+ method: "GET",
2840
+ path: "/fee-payout-destination"
2841
+ });
2842
+ }
2843
+ /**
2844
+ * Register or replace your fee payout destination.
2845
+ *
2846
+ * There is exactly one destination per organization, so this REPLACES any
2847
+ * existing one. Emits `fee_payout_destination.updated`.
2848
+ *
2849
+ * `chain` is a CAIP-2 chain id (e.g. `eip155:8453`) from the supported
2850
+ * networks list — see `client.info.getNetworks()`.
2851
+ *
2852
+ * @param data - The USDC wallet to pay fees to
2853
+ * @param options - Request options (e.g., custom idempotency key)
2854
+ * @returns The stored destination
2855
+ *
2856
+ * @example
2857
+ * ```typescript
2858
+ * const dest = await client.feePayoutDestination.set({
2859
+ * usdc_wallet: {
2860
+ * chain: 'eip155:8453',
2861
+ * address: '0x1234567890123456789012345678901234567890',
2862
+ * },
2863
+ * });
2864
+ * ```
2865
+ */
2866
+ async set(data, options) {
2867
+ return this.transport.request({
2868
+ method: "PUT",
2869
+ path: "/fee-payout-destination",
2870
+ body: data,
2871
+ idempotencyKey: options?.idempotencyKey
2872
+ });
2873
+ }
2874
+ /**
2875
+ * Remove the registered fee payout destination, if one exists.
2876
+ *
2877
+ * Emits `fee_payout_destination.deleted`.
2878
+ *
2879
+ * @example
2880
+ * ```typescript
2881
+ * await client.feePayoutDestination.delete();
2882
+ * ```
2883
+ */
2884
+ async delete() {
2885
+ await this.transport.request({
2886
+ method: "DELETE",
2887
+ path: "/fee-payout-destination"
2888
+ });
2889
+ }
2890
+ };
2891
+
2892
+ // src/client/resources/payment-agents.ts
2893
+ var PaymentAgentsResource = class extends BaseResource {
2894
+ /**
2895
+ * Create a hosted payment agent.
2896
+ *
2897
+ * @param data - Payment agent creation data (customer_id, name, hosted)
2898
+ * @returns The created payment agent (id, signer_id, signer_public_key, state)
2899
+ */
2900
+ async create(data, options) {
2901
+ return this.transport.request({
2902
+ method: "POST",
2903
+ path: "/payment-agents",
2904
+ body: data,
2905
+ idempotencyKey: options?.idempotencyKey
2906
+ });
2907
+ }
2908
+ /**
2909
+ * Get a hosted payment agent.
2910
+ *
2911
+ * Returns the agent together with the wallets it can currently spend
2912
+ * from. `wallet_ids` are DERIVED at query time from the agent signer's
2913
+ * live signer-group membership, so they reflect the agent's access
2914
+ * right now — not just at creation time.
2915
+ *
2916
+ * @param paymentAgentId - Payment agent ID
2917
+ */
2918
+ async get(paymentAgentId) {
2919
+ return this.transport.request({
2920
+ method: "GET",
2921
+ path: `/payment-agents/${paymentAgentId}`
2922
+ });
2923
+ }
2924
+ /**
2925
+ * Revoke a hosted payment agent.
2926
+ *
2927
+ * The agent can no longer be used, and its signing key is destroyed
2928
+ * in the isolated signer service (best-effort — the revoked state is
2929
+ * authoritative). Idempotent.
2930
+ *
2931
+ * The response's `signer_group_cleanup` names the signer groups the
2932
+ * (now-revoked) agent's signer still belongs to. A revoked signer can't
2933
+ * sign, but its group membership lingers — remove it with
2934
+ * `client.signerGroups.removeSigner(signer_group_id, signer_id)` to
2935
+ * finish de-provisioning.
2936
+ *
2937
+ * @param paymentAgentId - Payment agent ID
2938
+ * @returns The revoked payment agent (state=revoked, signer_group_cleanup?)
2939
+ */
2940
+ async revoke(paymentAgentId, options) {
2941
+ return this.transport.request({
2942
+ method: "POST",
2943
+ path: `/payment-agents/${paymentAgentId}/revoke`,
2944
+ idempotencyKey: options?.idempotencyKey
2945
+ });
2946
+ }
2947
+ /**
2948
+ * Draft payment proposals from a conversation.
2949
+ *
2950
+ * Pure cognition, no side effects: turn a customer's natural-language
2951
+ * request into reviewable proposals. Stateless — send the whole
2952
+ * conversation so far in `messages` on each call. Prefer
2953
+ * `AgentConversation` for multi-turn chat; use this directly only for
2954
+ * one-shot proposals.
2955
+ *
2956
+ * @param paymentAgentId - Payment agent ID
2957
+ * @param data - Prompt and/or messages
2958
+ * @returns Proposals (at high confidence) and/or a conversational reply
2959
+ */
2960
+ async createProposals(paymentAgentId, data, options) {
2961
+ return this.transport.request({
2962
+ method: "POST",
2963
+ path: `/payment-agents/${paymentAgentId}/proposals`,
2964
+ body: data,
2965
+ idempotencyKey: options?.idempotencyKey
2966
+ });
2967
+ }
2968
+ /**
2969
+ * Live progress of an in-flight drafting turn.
2970
+ *
2971
+ * A multi-payee drafting turn legitimately runs minutes (several sequential
2972
+ * model calls). While a `createProposals` call is in flight, poll this every
2973
+ * few seconds to show the customer what the agent is doing right now.
2974
+ *
2975
+ * Advisory display only. `active: false` means no turn is currently
2976
+ * publishing progress for this agent — idle, just finished, or served by
2977
+ * another instance — so fall back to a generic spinner. Never gate any
2978
+ * behaviour on this endpoint.
2979
+ *
2980
+ * The snapshot is coarse and customer-safe: a phase enum, one human
2981
+ * sentence, and the model round. Tool counts only — never payee names,
2982
+ * amounts, or addresses.
2983
+ *
2984
+ * @param paymentAgentId - Payment agent ID
2985
+ * @returns The current progress snapshot
2986
+ *
2987
+ * @example
2988
+ * ```typescript
2989
+ * const pending = client.paymentAgents.createProposals(agentId, { prompt });
2990
+ * const poll = setInterval(async () => {
2991
+ * const p = await client.paymentAgents.getProposalsProgress(agentId);
2992
+ * if (p.active) console.log(p.detail);
2993
+ * }, 3000);
2994
+ * const result = await pending.finally(() => clearInterval(poll));
2995
+ * ```
2996
+ */
2997
+ async getProposalsProgress(paymentAgentId) {
2998
+ return this.transport.request({
2999
+ method: "GET",
3000
+ path: `/payment-agents/${paymentAgentId}/proposals/progress`
3001
+ });
3002
+ }
3003
+ };
3004
+
3005
+ // src/client/resources/instructions.ts
3006
+ var InstructionsResource = class extends BaseResource {
3007
+ /**
3008
+ * Accept proposals — actuate them into persisted instructions.
3009
+ *
3010
+ * @param data - The payment agent id and the proposals to accept
3011
+ * @returns instruction_ids + the mandates the batch drafted (in full
3012
+ * wire shape; sign the §8 approval immediately)
3013
+ */
3014
+ async create(data, options) {
3015
+ return this.transport.request({
3016
+ method: "POST",
3017
+ path: "/instructions",
3018
+ body: data,
3019
+ idempotencyKey: options?.idempotencyKey
3020
+ });
3021
+ }
3022
+ /**
3023
+ * Get an accepted instruction — its action series and the per-action
3024
+ * downstream artifacts actuation produced.
3025
+ *
3026
+ * @param instructionId - Instruction ID
3027
+ */
3028
+ async get(instructionId) {
3029
+ return this.transport.request({
3030
+ method: "GET",
3031
+ path: `/instructions/${instructionId}`
3032
+ });
3033
+ }
3034
+ };
3035
+
3036
+ // src/client/resources/mandates.ts
3037
+ var MandatesResource = class extends BaseResource {
3038
+ /**
3039
+ * List mandates (newest first), with the EFFECTIVE status — a pending or
3040
+ * active mandate past its valid_until reads "expired". Filter with
3041
+ * customer_id / signer_id / status; omit them all for the full collection.
3042
+ *
3043
+ * @param params - Optional pagination + filter parameters
3044
+ * @returns Async iterator of mandates
3045
+ */
3046
+ list(params) {
3047
+ return this.paginate("/mandates", params);
3048
+ }
3049
+ /**
3050
+ * Get a mandate — the signer it binds, its rule exactly as the customer
3051
+ * approves it, validity, and status.
3052
+ *
3053
+ * @param mandateId - Mandate ID
3054
+ */
3055
+ async get(mandateId) {
3056
+ return this.transport.request({
3057
+ method: "GET",
3058
+ path: `/mandates/${mandateId}`
3059
+ });
3060
+ }
3061
+ /**
3062
+ * Create a mandate directly.
3063
+ *
3064
+ * Drafts a PENDING mandate from a direct user interaction — no instruction
3065
+ * back-link. Exactly one binding form names the signer the mandate binds:
3066
+ * `payment_agent_id` (hosted convenience — binds that agent's signer and
3067
+ * anchors to the agent's customer), or `signer_id` together with
3068
+ * `customer_id` (any of the client's signers, BYO keys included). The rule
3069
+ * is the one the customer will approve (via `approve`, a recognized signer
3070
+ * other than the bound one, §8).
3071
+ *
3072
+ * @param data - One binding form + rule + optional validity window
3073
+ * @returns The drafted (pending) mandate
3074
+ */
3075
+ async create(data, options) {
3076
+ return this.transport.request({
3077
+ method: "POST",
3078
+ path: "/mandates",
3079
+ body: data,
3080
+ idempotencyKey: options?.idempotencyKey
3081
+ });
3082
+ }
3083
+ /**
3084
+ * Approve a mandate.
3085
+ *
3086
+ * A recognized signer OTHER than the bound one signs the mandate payload
3087
+ * (see `mandateSignPayload` + `MandateSigner`) to activate it; arms its
3088
+ * scheduled payments.
3089
+ *
3090
+ * @param mandateId - Mandate ID
3091
+ * @param data - Approver public key (base64 PKIX) + base64 ASN.1 signature
3092
+ */
3093
+ async approve(mandateId, data, options) {
3094
+ return this.transport.request({
3095
+ method: "POST",
3096
+ path: `/mandates/${mandateId}/approve`,
3097
+ body: data,
3098
+ idempotencyKey: options?.idempotencyKey
3099
+ });
3100
+ }
3101
+ /**
3102
+ * Cancel a mandate.
3103
+ *
3104
+ * Revokes a pending or active mandate. The canceller must be a recognized
3105
+ * signer OTHER than the bound one, with a valid signature over the mandate
3106
+ * payload — the bound signer can never mutate its own mandate.
3107
+ *
3108
+ * @param mandateId - Mandate ID
3109
+ * @param data - Signer public key (base64 PKIX) + base64 ASN.1 signature
3110
+ */
3111
+ async cancel(mandateId, data, options) {
3112
+ return this.transport.request({
3113
+ method: "POST",
3114
+ path: `/mandates/${mandateId}/cancel`,
3115
+ body: data,
3116
+ idempotencyKey: options?.idempotencyKey
3117
+ });
3118
+ }
3119
+ /**
3120
+ * Amend a mandate — append a new signed version of its rule.
3121
+ *
3122
+ * Carries a changed rule into force with ONE signature and WITHOUT resetting
3123
+ * the spend already made in the current window: usage accrues to the
3124
+ * MANDATE, so an agent that has spent 9,000 of a 10,000 monthly limit and is
3125
+ * amended to 20,000 has 11,000 left, not 20,000.
3126
+ *
3127
+ * The `rule` is stored and verified VERBATIM — this endpoint does not
3128
+ * normalize it. It must already be canonical: `window` present and non-empty
3129
+ * (send `'NONE'` for a lifetime window), `targets` as recipient ids rather
3130
+ * than payee names, and `asset` uppercase. `target_type`, `window`, `asset`
3131
+ * and `network_id` must also match the current version exactly; only the
3132
+ * amount fields and `targets` may differ. Anything else is a 400 naming the
3133
+ * offending field.
3134
+ *
3135
+ * Build `signature` from `mandateAmendSignPayload(mandate, version, rule)` —
3136
+ * the amend payload commits to the version being created, so a signature for
3137
+ * v2 can never be replayed to append v3.
3138
+ *
3139
+ * @param mandateId - Mandate ID
3140
+ * @param data - Amending signer public key + signature + the complete NEW rule
3141
+ * @returns The mandate at its new current version
3142
+ *
3143
+ * @example
3144
+ * ```typescript
3145
+ * const mandate = await client.mandates.get(mandateId);
3146
+ * const nextVersion = (mandate.version ?? 1) + 1;
3147
+ * const rule = { ...mandate.rule, max_amount_in_window: '20000' };
3148
+ * const payload = mandateAmendSignPayload(mandate, nextVersion, rule);
3149
+ *
3150
+ * const amended = await client.mandates.amend(mandateId, {
3151
+ * signer_public_key: signer.publicKeyBase64(),
3152
+ * signature: await signer.sign(payload),
3153
+ * rule,
3154
+ * });
3155
+ * ```
3156
+ */
3157
+ async amend(mandateId, data, options) {
3158
+ return this.transport.request({
3159
+ method: "POST",
3160
+ path: `/mandates/${mandateId}/amend`,
3161
+ body: data,
3162
+ idempotencyKey: options?.idempotencyKey
3163
+ });
3164
+ }
3165
+ /**
3166
+ * List a mandate's versions, oldest first.
3167
+ *
3168
+ * The append-only history of every rule that was ever in force under this
3169
+ * mandate, and the §8 signer that put each one there. Versions are
3170
+ * immutable, so a rule listed here never changes — this is what makes an
3171
+ * executed payment's `mandate_version` audit stamp legible.
3172
+ *
3173
+ * @param mandateId - Mandate ID
3174
+ * @returns Every version, oldest first
3175
+ */
3176
+ async listVersions(mandateId) {
3177
+ return this.transport.request({
3178
+ method: "GET",
3179
+ path: `/mandates/${mandateId}/versions`
3180
+ });
3181
+ }
3182
+ /**
3183
+ * Get a mandate's remaining budget right now.
3184
+ *
3185
+ * The mandate's `rule` gives the ceilings; this gives the CONSUMPTION — what
3186
+ * has already been spent, what is earmarked by scheduled payments that have
3187
+ * not fired yet, and therefore what is left. Read it before scheduling:
3188
+ * otherwise an over-budget payment is only discovered when the gate denies
3189
+ * it at its due date, days later, with the payee unpaid.
3190
+ *
3191
+ * Advisory — nothing here reserves budget, and the gate remains the
3192
+ * authority at fire time. Two things to honour when reading a line:
3193
+ * an ABSENT `remaining_amount` / `remaining_count` means "not capped", never
3194
+ * "nothing left"; a `remaining_amount` of `'?'` means the figure could not
3195
+ * be summed and MUST be treated as no headroom (the gate fails closed on the
3196
+ * same data).
3197
+ *
3198
+ * @param mandateId - Mandate ID
3199
+ * @returns Per-target and aggregate budget lines, as of a stated instant
3200
+ *
3201
+ * @example
3202
+ * ```typescript
3203
+ * const budget = await client.mandates.getBudget(mandateId);
3204
+ * for (const line of budget.aggregate) {
3205
+ * console.log(line.bucket, line.remaining_amount ?? 'uncapped');
3206
+ * }
3207
+ * ```
3208
+ */
3209
+ async getBudget(mandateId) {
3210
+ return this.transport.request({
3211
+ method: "GET",
3212
+ path: `/mandates/${mandateId}/budget`
3213
+ });
3214
+ }
3215
+ };
3216
+
3217
+ // src/client/resources/scheduled-payments.ts
3218
+ var ScheduledPaymentsResource = class extends BaseResource {
3219
+ /**
3220
+ * List scheduled payments (oldest due first).
3221
+ *
3222
+ * Narrow the collection with the optional customer_id, signer_id,
3223
+ * wallet_id, mandate_id, and status filters; omit them all for the full
3224
+ * client collection.
3225
+ *
3226
+ * @param params - Optional pagination + filter parameters
3227
+ * @returns Async iterator of scheduled payments
3228
+ */
3229
+ list(params) {
3230
+ return this.paginate("/scheduled-payments", params);
3231
+ }
3232
+ /**
3233
+ * Schedule payments directly — bypass the proposal flow.
3234
+ *
3235
+ * Creates one or more scheduled payments for a signer under an existing
3236
+ * active mandate (coverage is matched at fire time, so no new signature
3237
+ * is needed here). The schedule is explicit `dates` OR `count` ×
3238
+ * `interval_seconds` from `start_at`.
3239
+ *
3240
+ * @param data - Signer + wallet + destination (or address+network_id) + schedule
3241
+ * @returns The rows that were created (one per date)
3242
+ */
3243
+ async create(data, options) {
3244
+ return this.transport.request({
3245
+ method: "POST",
3246
+ path: "/scheduled-payments",
3247
+ body: data,
3248
+ idempotencyKey: options?.idempotencyKey
3249
+ });
3250
+ }
3251
+ /**
3252
+ * Cancel one still-scheduled payment.
3253
+ *
3254
+ * Finalizes the row as cancelled. No signature is required — schedule rows
3255
+ * are bookkeeping, not authorization; the signed grant is the MANDATE,
3256
+ * which this does not touch.
3257
+ *
3258
+ * @param scheduledPaymentId - Scheduled payment ID
3259
+ */
3260
+ async cancel(scheduledPaymentId, options) {
3261
+ await this.transport.request({
3262
+ method: "POST",
3263
+ path: `/scheduled-payments/${scheduledPaymentId}/cancel`,
3264
+ idempotencyKey: options?.idempotencyKey
3265
+ });
3266
+ }
3267
+ };
3268
+
3269
+ // src/client/resources/insights.ts
3270
+ var InsightsResource = class extends BaseResource {
3271
+ /**
3272
+ * Get the customer's account insight report.
3273
+ *
3274
+ * A deterministic, read-only report: a snapshot of typed facts
3275
+ * (funding-wallet balances, upcoming totals, open payments, active
3276
+ * mandates), observations (`insights`), and advisory recommendations
3277
+ * (`suggestions`). Every item carries `evidence` — typed references to
3278
+ * the platform objects it was computed from. `kind` is an OPEN set;
3279
+ * ignore kinds you do not recognize.
3280
+ *
3281
+ * @param customerId - Customer ID
3282
+ * @returns The customer's insight report
3283
+ */
3284
+ async get(customerId) {
3285
+ return this.transport.request({
3286
+ method: "GET",
3287
+ path: `/customers/${customerId}/insights`
3288
+ });
3289
+ }
3290
+ /**
3291
+ * Ask about the customer's account.
3292
+ *
3293
+ * A read-only, advisory conversation. Stateless: send the conversation so
3294
+ * far in `messages` on each call; the response is the assistant's next
3295
+ * plain-text `reply`. The assistant narrates the same deterministic report
3296
+ * {@link get} returns — it never originates a number, never proposes, and
3297
+ * never moves money. Rate-limited per customer (hourly burst + daily
3298
+ * window) — a 429 means back off and retry later.
3299
+ *
3300
+ * @param customerId - Customer ID
3301
+ * @param data - The conversation so far (1–40 messages)
3302
+ * @returns The assistant's reply (+ how the boundary screen treated the turn)
3303
+ */
3304
+ async chat(customerId, data, options) {
3305
+ return this.transport.request({
3306
+ method: "POST",
3307
+ path: `/customers/${customerId}/insights/chat`,
3308
+ body: data,
3309
+ idempotencyKey: options?.idempotencyKey
3310
+ });
3311
+ }
3312
+ };
3313
+
3314
+ // src/agentic/chat.ts
3315
+ var AgentConversation = class {
3316
+ client;
3317
+ paymentAgentId;
3318
+ timezone;
3319
+ history = [];
3320
+ constructor(client, paymentAgentId, history, options) {
3321
+ this.client = client;
3322
+ this.paymentAgentId = paymentAgentId;
3323
+ this.timezone = options?.timezone;
3324
+ if (history && history.length > 0) {
3325
+ this.history = history.map(cloneMessage);
3326
+ }
3327
+ }
3328
+ /**
3329
+ * Adds the user's message to the transcript, asks the agent, records the
3330
+ * agent's reply, and returns the turn. When `hasProposals` is true the
3331
+ * agent has drafted a reviewable action series; otherwise `reply` holds
3332
+ * its next question.
3333
+ *
3334
+ * On error the optimistic user turn is rolled back, so the caller may
3335
+ * retry the same call without duplicating it.
3336
+ */
3337
+ async send(userMessage) {
3338
+ return this.sendWithAttachments(userMessage);
3339
+ }
3340
+ /**
3341
+ * {@link send} with documents (e.g. an invoice PDF) attached to the user
3342
+ * turn for the agent to read and draft payments from. Same turn semantics
3343
+ * and rollback-on-error behavior as `send`. Attachments ride only on the
3344
+ * turn they are passed; the stateless transcript keeps the agent's text
3345
+ * reply, so a follow-up turn relies on that summary rather than re-sending
3346
+ * the document.
3347
+ */
3348
+ async sendWithAttachments(userMessage, attachments) {
3349
+ const hasAttachments = attachments !== void 0 && attachments.length > 0;
3350
+ this.history.push({
3351
+ role: "user",
3352
+ content: userMessage,
3353
+ ...hasAttachments ? { attachments } : {}
3354
+ });
3355
+ const messages = this.history.map(serializeMessage);
3356
+ if (hasAttachments) {
3357
+ const last = this.history[this.history.length - 1];
3358
+ if (last) {
3359
+ delete last.attachments;
3360
+ }
3361
+ }
3362
+ let result;
3363
+ try {
3364
+ result = await this.client.paymentAgents.createProposals(this.paymentAgentId, {
3365
+ messages,
3366
+ // Resent on EVERY turn — the endpoint is stateless, so a zone given
3367
+ // once would be forgotten on the next one.
3368
+ ...this.timezone ? { timezone: this.timezone } : {}
3369
+ });
3370
+ } catch (err) {
3371
+ this.history.pop();
3372
+ throw err;
3373
+ }
3374
+ const turn = {
3375
+ reply: result.reply ?? "",
3376
+ proposals: result.proposals ? [...result.proposals] : [],
3377
+ hasProposals: !!result.proposals && result.proposals.length > 0,
3378
+ conversationStatus: result.conversation_status ?? ""
3379
+ };
3380
+ let assistant = turn.reply;
3381
+ if (!assistant) {
3382
+ assistant = turn.hasProposals ? "(drafted proposals for your review)" : "(no reply)";
3383
+ }
3384
+ this.history.push({ role: "assistant", content: assistant });
3385
+ return turn;
3386
+ }
3387
+ /**
3388
+ * A copy of the full transcript so far. Persist this between requests in
3389
+ * a stateless backend and rebuild with
3390
+ * {@link DakotaClient.resumeAgentConversation}.
3391
+ */
3392
+ messages() {
3393
+ return this.history.map(cloneMessage);
3394
+ }
3395
+ };
3396
+ function cloneMessage(m) {
3397
+ const out = { role: m.role, content: m.content };
3398
+ if (m.attachments && m.attachments.length > 0) {
3399
+ out.attachments = m.attachments.map((a) => ({ ...a }));
3400
+ }
3401
+ return out;
3402
+ }
3403
+ function serializeMessage(m) {
3404
+ const out = { role: m.role, content: m.content };
3405
+ if (m.attachments && m.attachments.length > 0) {
3406
+ out.attachments = m.attachments.map((a) => {
3407
+ const document = {
3408
+ media_type: a.mediaType,
3409
+ data: Buffer.from(a.data).toString("base64")
3410
+ };
3411
+ if (a.filename) {
3412
+ document.filename = a.filename;
3413
+ }
3414
+ return { type: "document", document };
3415
+ });
3416
+ }
3417
+ return out;
3418
+ }
3419
+ async function attachUserToWallet(client, walletId, signerPublicKey, spendingGroupId, options) {
3420
+ if (!walletId || !signerPublicKey || !spendingGroupId) {
3421
+ throw new Error("walletId, signerPublicKey and spendingGroupId are all required");
3422
+ }
3423
+ await requireGroupOnWallet(client, walletId, spendingGroupId);
3424
+ const group = await client.signerGroups.get(spendingGroupId);
3425
+ for (const member of group.members ?? []) {
3426
+ if (member.public_key === signerPublicKey) {
3427
+ return { alreadyMember: true };
3428
+ }
3429
+ }
3430
+ await client.signerGroups.addSigner(
3431
+ spendingGroupId,
3432
+ { member_key: signerPublicKey },
3433
+ { idempotencyKey: options?.idempotencyKey ?? crypto.randomUUID() }
3434
+ );
3435
+ return { alreadyMember: false };
3436
+ }
3437
+ async function detachUserFromWallet(client, walletId, signerPublicKey, spendingGroupId, options) {
3438
+ if (!walletId || !signerPublicKey || !spendingGroupId) {
3439
+ throw new Error("walletId, signerPublicKey and spendingGroupId are all required");
3440
+ }
3441
+ await requireGroupOnWallet(client, walletId, spendingGroupId);
3442
+ const group = await client.signerGroups.get(spendingGroupId);
3443
+ let signerId = "";
3444
+ for (const member of group.members ?? []) {
3445
+ if (member.public_key === signerPublicKey) {
3446
+ signerId = member.id ?? "";
3447
+ break;
3448
+ }
3449
+ }
3450
+ if (!signerId) {
3451
+ return { wasMember: false };
3452
+ }
3453
+ await client.signerGroups.removeSigner(spendingGroupId, signerId, {
3454
+ idempotencyKey: options?.idempotencyKey ?? crypto.randomUUID()
3455
+ });
3456
+ return { wasMember: true };
3457
+ }
3458
+ async function requireGroupOnWallet(client, walletId, spendingGroupId) {
3459
+ const wallets = await client.signerGroups.getWallets(spendingGroupId);
3460
+ for (const w of wallets) {
3461
+ if (w.id === walletId) {
3462
+ return;
3463
+ }
3464
+ }
3465
+ throw new Error(`signer group ${spendingGroupId} is not attached to wallet ${walletId}`);
3466
+ }
3467
+
2628
3468
  // src/client/client.ts
2629
3469
  var DakotaClient = class {
2630
3470
  config;
@@ -2666,6 +3506,18 @@ var DakotaClient = class {
2666
3506
  sandbox;
2667
3507
  /** Self-Serve Credits API - manage prepaid transfer credits */
2668
3508
  selfServe;
3509
+ /** Fee Payout Destination API - where Dakota pays your accrued developer fees */
3510
+ feePayoutDestination;
3511
+ /** Payment Agents API (ALPHA) - hosted signing agents that draft payments */
3512
+ paymentAgents;
3513
+ /** Instructions API (ALPHA) - accept and inspect actuated proposals */
3514
+ instructions;
3515
+ /** Mandates API (ALPHA) - the §8 authorizations that arm scheduled payments */
3516
+ mandates;
3517
+ /** Scheduled Payments API (ALPHA) - schedule rows created from instructions */
3518
+ scheduledPayments;
3519
+ /** Insights API (ALPHA) - read-only advisory reporting over agentic activity */
3520
+ insights;
2669
3521
  /**
2670
3522
  * Create a new Dakota client.
2671
3523
  *
@@ -2719,6 +3571,61 @@ var DakotaClient = class {
2719
3571
  this.info = new InfoResource(this.transport);
2720
3572
  this.sandbox = new SandboxResource(this.transport);
2721
3573
  this.selfServe = new SelfServeResource(this.transport);
3574
+ this.feePayoutDestination = new FeePayoutDestinationResource(this.transport);
3575
+ this.paymentAgents = new PaymentAgentsResource(this.transport);
3576
+ this.instructions = new InstructionsResource(this.transport);
3577
+ this.mandates = new MandatesResource(this.transport);
3578
+ this.scheduledPayments = new ScheduledPaymentsResource(this.transport);
3579
+ this.insights = new InsightsResource(this.transport);
3580
+ }
3581
+ // ==========================================================================
3582
+ // Agentic Payments high-level helpers (ALPHA)
3583
+ //
3584
+ // Collapse the multi-step, crypto-heavy hosted-agent flows into single
3585
+ // calls with good defaults. The raw operations remain reachable via
3586
+ // `signerGroups.addSigner` / `signerGroups.removeSigner` and friends.
3587
+ // ==========================================================================
3588
+ /**
3589
+ * Start a fresh multi-turn conversation with a payment agent.
3590
+ *
3591
+ * Pass `{ timezone }` (an IANA zone) so the agent resolves "tomorrow" and
3592
+ * "10 am" in the customer's local time rather than UTC. The conversation
3593
+ * resends it on every turn.
3594
+ *
3595
+ * @see AgentConversation
3596
+ */
3597
+ newAgentConversation(paymentAgentId, options) {
3598
+ return new AgentConversation(this, paymentAgentId, void 0, options);
3599
+ }
3600
+ /**
3601
+ * Rebuild a conversation from a persisted transcript (oldest first) —
3602
+ * for backends that store the history between requests.
3603
+ *
3604
+ * A stateless backend must pass `{ timezone }` again here: the transcript
3605
+ * carries the messages, not the zone.
3606
+ */
3607
+ resumeAgentConversation(paymentAgentId, history, options) {
3608
+ return new AgentConversation(this, paymentAgentId, history, options);
3609
+ }
3610
+ /**
3611
+ * Grant a principal (user or agent — both are just signers) permission to
3612
+ * spend from a wallet by adding its signer to an EXISTING signer group on
3613
+ * that wallet. Idempotent; errors if the group isn't attached to the wallet.
3614
+ *
3615
+ * @see attachUserToWallet in `agentic/wallets.ts` for the full contract.
3616
+ */
3617
+ attachUserToWallet(walletId, signerPublicKey, spendingGroupId, options) {
3618
+ return attachUserToWallet(this, walletId, signerPublicKey, spendingGroupId, options);
3619
+ }
3620
+ /**
3621
+ * Revoke a principal's spend permission by removing its signer from the
3622
+ * given signer group — the inverse of {@link attachUserToWallet}.
3623
+ * Idempotent; errors if the group isn't attached to the wallet.
3624
+ *
3625
+ * @see detachUserFromWallet in `agentic/wallets.ts` for the full contract.
3626
+ */
3627
+ detachUserFromWallet(walletId, signerPublicKey, spendingGroupId, options) {
3628
+ return detachUserFromWallet(this, walletId, signerPublicKey, spendingGroupId, options);
2722
3629
  }
2723
3630
  /**
2724
3631
  * Get the resolved base URL.
@@ -2728,8 +3635,252 @@ var DakotaClient = class {
2728
3635
  }
2729
3636
  };
2730
3637
 
3638
+ // src/agentic/canonicalize.ts
3639
+ function canonicalJSON(value) {
3640
+ return canonicalize(value);
3641
+ }
3642
+ function canonicalize(value) {
3643
+ if (value === null || value === void 0) {
3644
+ return "null";
3645
+ }
3646
+ if (typeof value === "boolean") {
3647
+ return value ? "true" : "false";
3648
+ }
3649
+ if (typeof value === "number") {
3650
+ if (!Number.isFinite(value)) {
3651
+ throw new TypeError(`canonical JSON: non-finite number ${value}`);
3652
+ }
3653
+ return JSON.stringify(value);
3654
+ }
3655
+ if (typeof value === "string") {
3656
+ return JSON.stringify(value);
3657
+ }
3658
+ if (typeof value === "bigint") {
3659
+ throw new TypeError("canonical JSON: bigint values are not supported");
3660
+ }
3661
+ if (Array.isArray(value)) {
3662
+ const parts = value.map((item) => canonicalize(item));
3663
+ return `[${parts.join(",")}]`;
3664
+ }
3665
+ if (typeof value === "object") {
3666
+ const obj = value;
3667
+ const keys = Object.keys(obj).sort();
3668
+ const parts = keys.map((key) => `${JSON.stringify(key)}:${canonicalize(obj[key])}`);
3669
+ return `{${parts.join(",")}}`;
3670
+ }
3671
+ throw new TypeError(`canonical JSON: unsupported value type ${typeof value}`);
3672
+ }
3673
+
3674
+ // src/agentic/sign.ts
3675
+ function mandateSignPayload(mandate, action) {
3676
+ if (!mandate.id) {
3677
+ throw new Error("mandate has no id");
3678
+ }
3679
+ if (!mandate.bound_signer_id) {
3680
+ throw new Error("mandate has no bound_signer_id");
3681
+ }
3682
+ if (!mandate.rule) {
3683
+ throw new Error("mandate has no rule");
3684
+ }
3685
+ const encoded = canonicalJSON({
3686
+ action,
3687
+ id: mandate.id,
3688
+ bound_signer: mandate.bound_signer_id,
3689
+ rule: mandate.rule,
3690
+ valid_from: mandate.valid_from ?? 0,
3691
+ valid_until: mandate.valid_until ?? 0
3692
+ });
3693
+ return new TextEncoder().encode(encoded);
3694
+ }
3695
+ function mandateAmendSignPayload(mandate, version, rule) {
3696
+ if (!mandate.id) {
3697
+ throw new Error("mandate has no id");
3698
+ }
3699
+ if (!mandate.bound_signer_id) {
3700
+ throw new Error("mandate has no bound_signer_id");
3701
+ }
3702
+ if (!Number.isInteger(version) || version < 2) {
3703
+ throw new Error("amend version must be an integer >= 2 (the version being created)");
3704
+ }
3705
+ const encoded = canonicalJSON({
3706
+ action: "amend",
3707
+ id: mandate.id,
3708
+ bound_signer: mandate.bound_signer_id,
3709
+ rule,
3710
+ valid_from: mandate.valid_from ?? 0,
3711
+ valid_until: mandate.valid_until ?? 0,
3712
+ version
3713
+ });
3714
+ return new TextEncoder().encode(encoded);
3715
+ }
3716
+ function attachGroupPayload(walletId, groupId, idempotencyKey) {
3717
+ return textBytes(
3718
+ canonicalJSON({
3719
+ type: "attach_group_to_wallet",
3720
+ wallet_id: walletId,
3721
+ group_id: groupId,
3722
+ idempotency_key: idempotencyKey
3723
+ })
3724
+ );
3725
+ }
3726
+ function attachPolicyPayload(walletId, policyId, idempotencyKey) {
3727
+ return textBytes(
3728
+ canonicalJSON({
3729
+ type: "attach_policy_to_wallet",
3730
+ wallet_id: walletId,
3731
+ policy_id: policyId,
3732
+ idempotency_key: idempotencyKey
3733
+ })
3734
+ );
3735
+ }
3736
+ function detachGroupPayload(walletId, groupId, idempotencyKey) {
3737
+ return textBytes(
3738
+ canonicalJSON({
3739
+ type: "detach_group_from_wallet",
3740
+ wallet_id: walletId,
3741
+ group_id: groupId,
3742
+ idempotency_key: idempotencyKey
3743
+ })
3744
+ );
3745
+ }
3746
+ function detachPolicyPayload(walletId, policyId, idempotencyKey) {
3747
+ return textBytes(
3748
+ canonicalJSON({
3749
+ type: "detach_policy_from_wallet",
3750
+ wallet_id: walletId,
3751
+ policy_id: policyId,
3752
+ idempotency_key: idempotencyKey
3753
+ })
3754
+ );
3755
+ }
3756
+ function deletePolicyPayload(policyId, idempotencyKey) {
3757
+ return textBytes(
3758
+ canonicalJSON({
3759
+ type: "delete_policy",
3760
+ policy_id: policyId,
3761
+ idempotency_key: idempotencyKey
3762
+ })
3763
+ );
3764
+ }
3765
+ function removePolicyRulePayload(policyId, ruleId, idempotencyKey) {
3766
+ return textBytes(
3767
+ canonicalJSON({
3768
+ type: "remove_policy_rule",
3769
+ policy_id: policyId,
3770
+ rule_id: ruleId,
3771
+ idempotency_key: idempotencyKey
3772
+ })
3773
+ );
3774
+ }
3775
+ function updatePolicyRulePayload(policyId, ruleId, updatedDefinition, idempotencyKey) {
3776
+ return textBytes(
3777
+ canonicalJSON({
3778
+ type: "update_policy_rule",
3779
+ policy_id: policyId,
3780
+ rule_id: ruleId,
3781
+ updated_definition: updatedDefinition,
3782
+ idempotency_key: idempotencyKey
3783
+ })
3784
+ );
3785
+ }
3786
+ function addPolicyRulePayload(policyId, action, ruleType, definition, idempotencyKey) {
3787
+ return textBytes(
3788
+ canonicalJSON({
3789
+ type: "add_policy_rule",
3790
+ action,
3791
+ rule_type: ruleType,
3792
+ policy_id: policyId,
3793
+ definition,
3794
+ idempotency_key: idempotencyKey
3795
+ })
3796
+ );
3797
+ }
3798
+ function textBytes(s) {
3799
+ return new TextEncoder().encode(s);
3800
+ }
3801
+ var P256MandateSigner = class _P256MandateSigner {
3802
+ privateKey;
3803
+ publicKey;
3804
+ constructor(privateKey, publicKey) {
3805
+ this.privateKey = privateKey;
3806
+ this.publicKey = publicKey;
3807
+ }
3808
+ /**
3809
+ * Generate a fresh P-256 keypair.
3810
+ */
3811
+ static generate() {
3812
+ const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "P-256" });
3813
+ return new _P256MandateSigner(privateKey, publicKey);
3814
+ }
3815
+ /**
3816
+ * Adopt an existing P-256 private key. Accepts a PKCS#8 PEM string, a
3817
+ * DER-encoded PKCS#8 buffer, or a Node {@link KeyObject}.
3818
+ */
3819
+ static fromPrivateKey(key) {
3820
+ const privateKey = typeof key === "string" || key instanceof Uint8Array ? crypto.createPrivateKey({
3821
+ key,
3822
+ format: typeof key === "string" ? "pem" : "der",
3823
+ type: "pkcs8"
3824
+ }) : key;
3825
+ if (privateKey.asymmetricKeyType !== "ec") {
3826
+ throw new Error("a P-256 private key is required (ES256)");
3827
+ }
3828
+ const details = privateKey.asymmetricKeyDetails;
3829
+ if (details?.namedCurve !== "prime256v1") {
3830
+ throw new Error("a P-256 private key is required (ES256)");
3831
+ }
3832
+ const publicKey = crypto.createPublicKey(privateKey);
3833
+ return new _P256MandateSigner(privateKey, publicKey);
3834
+ }
3835
+ /**
3836
+ * base64 PKIX (SPKI) public key — pass this as the signer's registered
3837
+ * public key at agent creation / mandate approval.
3838
+ */
3839
+ publicKeyBase64() {
3840
+ const der = this.publicKey.export({ format: "der", type: "spki" });
3841
+ return Buffer.from(der).toString("base64");
3842
+ }
3843
+ /**
3844
+ * Returns base64( ASN.1 ECDSA signature over SHA-256(payload) ).
3845
+ */
3846
+ sign(payload) {
3847
+ const signer = crypto.createSign("SHA256");
3848
+ signer.update(payload);
3849
+ const sig = signer.sign({ key: this.privateKey, dsaEncoding: "der" });
3850
+ return Buffer.from(sig).toString("base64");
3851
+ }
3852
+ };
3853
+ function verifyMandateSignature(publicKeyBase64, payload, signatureBase64) {
3854
+ let publicKey;
3855
+ try {
3856
+ publicKey = crypto.createPublicKey({
3857
+ key: Buffer.from(publicKeyBase64, "base64"),
3858
+ format: "der",
3859
+ type: "spki"
3860
+ });
3861
+ } catch (err) {
3862
+ throw new Error(`parse public key: ${err.message}`);
3863
+ }
3864
+ if (publicKey.asymmetricKeyType !== "ec") {
3865
+ throw new Error("not a P-256 public key (ES256 requires P-256)");
3866
+ }
3867
+ if (publicKey.asymmetricKeyDetails?.namedCurve !== "prime256v1") {
3868
+ throw new Error("not a P-256 public key (ES256 requires P-256)");
3869
+ }
3870
+ const verifier = crypto.createVerify("SHA256");
3871
+ verifier.update(payload);
3872
+ const ok = verifier.verify(
3873
+ { key: publicKey, dsaEncoding: "der" },
3874
+ Buffer.from(signatureBase64, "base64")
3875
+ );
3876
+ if (!ok) {
3877
+ throw new Error("signature verification failed");
3878
+ }
3879
+ }
3880
+
2731
3881
  exports.APIError = APIError;
2732
3882
  exports.AccountsResource = AccountsResource;
3883
+ exports.AgentConversation = AgentConversation;
2733
3884
  exports.ApiKeysResource = ApiKeysResource;
2734
3885
  exports.ApplicationsResource = ApplicationsResource;
2735
3886
  exports.AuthMode = AuthMode;
@@ -2741,11 +3892,18 @@ exports.DakotaClient = DakotaClient;
2741
3892
  exports.DestinationsResource = DestinationsResource;
2742
3893
  exports.Environment = Environment;
2743
3894
  exports.EventsResource = EventsResource;
3895
+ exports.FeePayoutDestinationResource = FeePayoutDestinationResource;
2744
3896
  exports.InfoResource = InfoResource;
3897
+ exports.InsightsResource = InsightsResource;
3898
+ exports.InstructionsResource = InstructionsResource;
3899
+ exports.MandatesResource = MandatesResource;
3900
+ exports.P256MandateSigner = P256MandateSigner;
2745
3901
  exports.PaginatedIterator = PaginatedIterator;
3902
+ exports.PaymentAgentsResource = PaymentAgentsResource;
2746
3903
  exports.PoliciesResource = PoliciesResource;
2747
3904
  exports.RecipientsResource = RecipientsResource;
2748
3905
  exports.SandboxResource = SandboxResource;
3906
+ exports.ScheduledPaymentsResource = ScheduledPaymentsResource;
2749
3907
  exports.SelfServeResource = SelfServeResource;
2750
3908
  exports.SignerGroupsResource = SignerGroupsResource;
2751
3909
  exports.SignersResource = SignersResource;
@@ -2754,9 +3912,23 @@ exports.TransportError = TransportError;
2754
3912
  exports.UsersResource = UsersResource;
2755
3913
  exports.WalletsResource = WalletsResource;
2756
3914
  exports.WebhooksResource = WebhooksResource;
3915
+ exports.addPolicyRulePayload = addPolicyRulePayload;
3916
+ exports.attachGroupPayload = attachGroupPayload;
3917
+ exports.attachPolicyPayload = attachPolicyPayload;
3918
+ exports.attachUserToWallet = attachUserToWallet;
3919
+ exports.canonicalJSON = canonicalJSON;
2757
3920
  exports.consoleLogger = consoleLogger;
3921
+ exports.deletePolicyPayload = deletePolicyPayload;
3922
+ exports.detachGroupPayload = detachGroupPayload;
3923
+ exports.detachPolicyPayload = detachPolicyPayload;
3924
+ exports.detachUserFromWallet = detachUserFromWallet;
2758
3925
  exports.getEnvironmentURL = getEnvironmentURL;
3926
+ exports.mandateAmendSignPayload = mandateAmendSignPayload;
3927
+ exports.mandateSignPayload = mandateSignPayload;
2759
3928
  exports.noopLogger = noopLogger;
2760
3929
  exports.paginate = paginate;
3930
+ exports.removePolicyRulePayload = removePolicyRulePayload;
3931
+ exports.updatePolicyRulePayload = updatePolicyRulePayload;
3932
+ exports.verifyMandateSignature = verifyMandateSignature;
2761
3933
  //# sourceMappingURL=index.js.map
2762
3934
  //# sourceMappingURL=index.js.map