@dakota-xyz/ts-sdk 3.0.0 → 3.4.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 +235 -36
- package/dist/governance/index.d.mts +315 -0
- package/dist/governance/index.d.ts +315 -0
- package/dist/governance/index.js +379 -0
- package/dist/governance/index.js.map +1 -0
- package/dist/governance/index.mjs +365 -0
- package/dist/governance/index.mjs.map +1 -0
- package/dist/index.d.mts +7274 -2928
- package/dist/index.d.ts +7274 -2928
- package/dist/index.js +1068 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1048 -148
- package/dist/index.mjs.map +1 -1
- package/dist/webhook/index.d.mts +179 -3
- package/dist/webhook/index.d.ts +179 -3
- package/dist/webhook/index.js +8 -0
- package/dist/webhook/index.js.map +1 -1
- package/dist/webhook/index.mjs +8 -0
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +15 -3
package/dist/index.mjs
CHANGED
|
@@ -116,7 +116,15 @@ var APIError = class _APIError extends Error {
|
|
|
116
116
|
}
|
|
117
117
|
} catch {
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
if (typeof code !== "string") {
|
|
120
|
+
code = `http_${response.status}`;
|
|
121
|
+
}
|
|
122
|
+
const governanceCode = code.replace(/-/g, "_");
|
|
123
|
+
const Typed = GOVERNANCE_ERRORS.get(governanceCode);
|
|
124
|
+
if (Typed) {
|
|
125
|
+
code = governanceCode;
|
|
126
|
+
}
|
|
127
|
+
return new (Typed ?? _APIError)(response.status, code, message, {
|
|
120
128
|
details,
|
|
121
129
|
requestId,
|
|
122
130
|
rawBody,
|
|
@@ -131,6 +139,50 @@ var APIError = class _APIError extends Error {
|
|
|
131
139
|
return `APIError [${this.statusCode}]: ${this.message}`;
|
|
132
140
|
}
|
|
133
141
|
};
|
|
142
|
+
var EndorsementRequiredError = class extends APIError {
|
|
143
|
+
constructor(statusCode, code, message, options) {
|
|
144
|
+
super(statusCode, code, message, options);
|
|
145
|
+
this.name = "EndorsementRequiredError";
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var InsufficientEndorsementsError = class extends APIError {
|
|
149
|
+
/** Signatures the platform counted, when it said so. */
|
|
150
|
+
have;
|
|
151
|
+
/** Signatures the quorum needs, when it said so. */
|
|
152
|
+
need;
|
|
153
|
+
constructor(statusCode, code, message, options) {
|
|
154
|
+
super(statusCode, code, message, options);
|
|
155
|
+
this.name = "InsufficientEndorsementsError";
|
|
156
|
+
const m = /have (\d+), need (\d+)/.exec(message);
|
|
157
|
+
this.have = m ? Number(m[1]) : null;
|
|
158
|
+
this.need = m ? Number(m[2]) : null;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var StaleSignerGroupVersionError = class extends APIError {
|
|
162
|
+
constructor(statusCode, code, message, options) {
|
|
163
|
+
super(statusCode, code, message, options);
|
|
164
|
+
this.name = "StaleSignerGroupVersionError";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var BelowThresholdError = class extends APIError {
|
|
168
|
+
constructor(statusCode, code, message, options) {
|
|
169
|
+
super(statusCode, code, message, options);
|
|
170
|
+
this.name = "BelowThresholdError";
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var InvalidGoverningGroupError = class extends APIError {
|
|
174
|
+
constructor(statusCode, code, message, options) {
|
|
175
|
+
super(statusCode, code, message, options);
|
|
176
|
+
this.name = "InvalidGoverningGroupError";
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var GOVERNANCE_ERRORS = /* @__PURE__ */ new Map([
|
|
180
|
+
["endorsement_required", EndorsementRequiredError],
|
|
181
|
+
["insufficient_endorsements", InsufficientEndorsementsError],
|
|
182
|
+
["stale_signer_group_version", StaleSignerGroupVersionError],
|
|
183
|
+
["below_threshold", BelowThresholdError],
|
|
184
|
+
["invalid_governing_group", InvalidGoverningGroupError]
|
|
185
|
+
]);
|
|
134
186
|
var TransportError = class _TransportError extends Error {
|
|
135
187
|
/** The underlying error that caused this transport error */
|
|
136
188
|
cause;
|
|
@@ -275,7 +327,7 @@ var Transport = class {
|
|
|
275
327
|
* Make an HTTP request with automatic retry and error handling.
|
|
276
328
|
*/
|
|
277
329
|
async request(options) {
|
|
278
|
-
const { method, path, body, query, headers, idempotencyKey, signal } = options;
|
|
330
|
+
const { method, path, body, query, headers, idempotencyKey, signal, noContent } = options;
|
|
279
331
|
const url = this.buildURL(path, query);
|
|
280
332
|
const requestHeaders = this.buildHeaders(method, path, headers, idempotencyKey);
|
|
281
333
|
const requestBody = body !== void 0 ? JSON.stringify(body) : void 0;
|
|
@@ -287,7 +339,8 @@ var Transport = class {
|
|
|
287
339
|
body: requestBody,
|
|
288
340
|
signal
|
|
289
341
|
},
|
|
290
|
-
this.resolveTimeout(options)
|
|
342
|
+
this.resolveTimeout(options),
|
|
343
|
+
noContent === true
|
|
291
344
|
);
|
|
292
345
|
}
|
|
293
346
|
/**
|
|
@@ -383,7 +436,7 @@ var Transport = class {
|
|
|
383
436
|
* deadline, so a request that keeps timing out can take up to
|
|
384
437
|
* `timeout × maxAttempts` before it throws.
|
|
385
438
|
*/
|
|
386
|
-
async executeWithRetry(url, init, timeout) {
|
|
439
|
+
async executeWithRetry(url, init, timeout, noContent = false) {
|
|
387
440
|
const { maxAttempts, initialBackoffMs, maxBackoffMs } = this.config.retryPolicy;
|
|
388
441
|
const method = init.method ?? "GET";
|
|
389
442
|
let lastError;
|
|
@@ -404,7 +457,7 @@ var Transport = class {
|
|
|
404
457
|
clearTimeout(timeoutId);
|
|
405
458
|
this.logResponse(method, url, response.status, attempt);
|
|
406
459
|
if (response.ok) {
|
|
407
|
-
if (response.status === 204) {
|
|
460
|
+
if (response.status === 204 || noContent) {
|
|
408
461
|
return void 0;
|
|
409
462
|
}
|
|
410
463
|
return await response.json();
|
|
@@ -870,6 +923,42 @@ var CustomersResource = class extends BaseResource {
|
|
|
870
923
|
timeout: options?.timeout
|
|
871
924
|
});
|
|
872
925
|
}
|
|
926
|
+
/**
|
|
927
|
+
* Withdraw a customer's onboarding application.
|
|
928
|
+
*
|
|
929
|
+
* Closes the application when the customer will not or cannot continue —
|
|
930
|
+
* for example after a request for information they chose not to answer.
|
|
931
|
+
*
|
|
932
|
+
* Withdrawal is FINAL. The application and its entities are recorded as
|
|
933
|
+
* withdrawn, the customer's `status` becomes `withdrawn`, and onboarding
|
|
934
|
+
* that customer again requires a new application. An application that
|
|
935
|
+
* already has a decision returns a 409.
|
|
936
|
+
*
|
|
937
|
+
* Emits `customer.application.withdrawn`.
|
|
938
|
+
*
|
|
939
|
+
* @param customerId - Customer ID (KSUID)
|
|
940
|
+
* @param applicationId - The customer's onboarding application ID
|
|
941
|
+
* @param data - Optional `reason`, recorded for audit and shown to reviewers
|
|
942
|
+
* @param options - Request options (e.g., custom idempotency key)
|
|
943
|
+
*
|
|
944
|
+
* @example
|
|
945
|
+
* ```typescript
|
|
946
|
+
* await client.customers.withdrawApplication(customerId, applicationId, {
|
|
947
|
+
* reason: 'Customer opted not to proceed',
|
|
948
|
+
* });
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
async withdrawApplication(customerId, applicationId, data = {}, options) {
|
|
952
|
+
await this.transport.request({
|
|
953
|
+
method: "POST",
|
|
954
|
+
path: `/customers/${customerId}/applications/${applicationId}/withdraw`,
|
|
955
|
+
body: data,
|
|
956
|
+
idempotencyKey: options?.idempotencyKey,
|
|
957
|
+
timeout: options?.timeout,
|
|
958
|
+
// The platform answers a bare 200 with no body.
|
|
959
|
+
noContent: true
|
|
960
|
+
});
|
|
961
|
+
}
|
|
873
962
|
/**
|
|
874
963
|
* Update the sub-client association for a customer.
|
|
875
964
|
*
|
|
@@ -1063,6 +1152,7 @@ var RecipientsResource = class extends BaseResource {
|
|
|
1063
1152
|
* ```typescript
|
|
1064
1153
|
* const recipient = await client.recipients.create(customerId, {
|
|
1065
1154
|
* name: 'Treasury Account',
|
|
1155
|
+
* external_id: 'vendor-1177', // optional: your own label, not unique
|
|
1066
1156
|
* });
|
|
1067
1157
|
* ```
|
|
1068
1158
|
*/
|
|
@@ -1079,7 +1169,7 @@ var RecipientsResource = class extends BaseResource {
|
|
|
1079
1169
|
* List recipients for a customer.
|
|
1080
1170
|
*
|
|
1081
1171
|
* @param customerId - Customer ID
|
|
1082
|
-
* @param params - Pagination parameters
|
|
1172
|
+
* @param params - Pagination parameters and an optional `external_id` filter
|
|
1083
1173
|
* @returns Async iterator of recipients
|
|
1084
1174
|
*
|
|
1085
1175
|
* @example
|
|
@@ -1087,6 +1177,11 @@ var RecipientsResource = class extends BaseResource {
|
|
|
1087
1177
|
* for await (const recipient of client.recipients.list(customerId)) {
|
|
1088
1178
|
* console.log(recipient.name);
|
|
1089
1179
|
* }
|
|
1180
|
+
*
|
|
1181
|
+
* // Look up recipients by your own label
|
|
1182
|
+
* const matches = await client.recipients
|
|
1183
|
+
* .list(customerId, { external_id: 'vendor-1177' })
|
|
1184
|
+
* .toArray();
|
|
1090
1185
|
* ```
|
|
1091
1186
|
*/
|
|
1092
1187
|
list(customerId, params) {
|
|
@@ -1150,6 +1245,211 @@ var RecipientsResource = class extends BaseResource {
|
|
|
1150
1245
|
}
|
|
1151
1246
|
};
|
|
1152
1247
|
|
|
1248
|
+
// src/agentic/canonicalize.ts
|
|
1249
|
+
function canonicalJSON(value) {
|
|
1250
|
+
return canonicalize(value);
|
|
1251
|
+
}
|
|
1252
|
+
function canonicalize(value) {
|
|
1253
|
+
if (value === null || value === void 0) {
|
|
1254
|
+
return "null";
|
|
1255
|
+
}
|
|
1256
|
+
if (typeof value === "boolean") {
|
|
1257
|
+
return value ? "true" : "false";
|
|
1258
|
+
}
|
|
1259
|
+
if (typeof value === "number") {
|
|
1260
|
+
if (!Number.isFinite(value)) {
|
|
1261
|
+
throw new TypeError(`canonical JSON: non-finite number ${value}`);
|
|
1262
|
+
}
|
|
1263
|
+
return JSON.stringify(value);
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof value === "string") {
|
|
1266
|
+
return JSON.stringify(value);
|
|
1267
|
+
}
|
|
1268
|
+
if (typeof value === "bigint") {
|
|
1269
|
+
throw new TypeError("canonical JSON: bigint values are not supported");
|
|
1270
|
+
}
|
|
1271
|
+
if (Array.isArray(value)) {
|
|
1272
|
+
const parts = value.map((item) => canonicalize(item));
|
|
1273
|
+
return `[${parts.join(",")}]`;
|
|
1274
|
+
}
|
|
1275
|
+
if (typeof value === "object") {
|
|
1276
|
+
const obj = value;
|
|
1277
|
+
const keys = Object.keys(obj).sort();
|
|
1278
|
+
const parts = keys.map((key) => `${JSON.stringify(key)}:${canonicalize(obj[key])}`);
|
|
1279
|
+
return `{${parts.join(",")}}`;
|
|
1280
|
+
}
|
|
1281
|
+
throw new TypeError(`canonical JSON: unsupported value type ${typeof value}`);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// src/governance/encoding.ts
|
|
1285
|
+
var B64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1286
|
+
function bytesToBase64(bytes) {
|
|
1287
|
+
let out = "";
|
|
1288
|
+
let i = 0;
|
|
1289
|
+
for (; i + 2 < bytes.length; i += 3) {
|
|
1290
|
+
const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
|
|
1291
|
+
out += B64_ALPHABET[n >> 18 & 63] + B64_ALPHABET[n >> 12 & 63] + B64_ALPHABET[n >> 6 & 63] + B64_ALPHABET[n & 63];
|
|
1292
|
+
}
|
|
1293
|
+
const rest = bytes.length - i;
|
|
1294
|
+
if (rest === 1) {
|
|
1295
|
+
const n = bytes[i] << 16;
|
|
1296
|
+
out += B64_ALPHABET[n >> 18 & 63] + B64_ALPHABET[n >> 12 & 63] + "==";
|
|
1297
|
+
} else if (rest === 2) {
|
|
1298
|
+
const n = bytes[i] << 16 | bytes[i + 1] << 8;
|
|
1299
|
+
out += B64_ALPHABET[n >> 18 & 63] + B64_ALPHABET[n >> 12 & 63] + B64_ALPHABET[n >> 6 & 63] + "=";
|
|
1300
|
+
}
|
|
1301
|
+
return out;
|
|
1302
|
+
}
|
|
1303
|
+
function bytesToBase64url(bytes) {
|
|
1304
|
+
return stripPadding(bytesToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_"));
|
|
1305
|
+
}
|
|
1306
|
+
function stripPadding(s) {
|
|
1307
|
+
let end = s.length;
|
|
1308
|
+
while (end > 0 && s.charCodeAt(end - 1) === 61) end--;
|
|
1309
|
+
return s.slice(0, end);
|
|
1310
|
+
}
|
|
1311
|
+
function base64ToBytes(input) {
|
|
1312
|
+
const s = stripPadding(input.replace(/-/g, "+").replace(/_/g, "/"));
|
|
1313
|
+
if (!/^[A-Za-z0-9+/]*$/.test(s) || s.length % 4 === 1) {
|
|
1314
|
+
throw new TypeError("invalid base64 or base64url string");
|
|
1315
|
+
}
|
|
1316
|
+
const out = new Uint8Array(Math.floor(s.length * 3 / 4));
|
|
1317
|
+
let o = 0;
|
|
1318
|
+
for (let i = 0; i < s.length; i += 4) {
|
|
1319
|
+
const a = B64_ALPHABET.indexOf(s[i]);
|
|
1320
|
+
const b = B64_ALPHABET.indexOf(s[i + 1]);
|
|
1321
|
+
const c = i + 2 < s.length ? B64_ALPHABET.indexOf(s[i + 2]) : 0;
|
|
1322
|
+
const d = i + 3 < s.length ? B64_ALPHABET.indexOf(s[i + 3]) : 0;
|
|
1323
|
+
const n = a << 18 | b << 12 | c << 6 | d;
|
|
1324
|
+
out[o++] = n >> 16 & 255;
|
|
1325
|
+
if (i + 2 < s.length) out[o++] = n >> 8 & 255;
|
|
1326
|
+
if (i + 3 < s.length) out[o++] = n & 255;
|
|
1327
|
+
}
|
|
1328
|
+
return out;
|
|
1329
|
+
}
|
|
1330
|
+
function utf8(s) {
|
|
1331
|
+
return new TextEncoder().encode(s);
|
|
1332
|
+
}
|
|
1333
|
+
function toBytes(source) {
|
|
1334
|
+
if (ArrayBuffer.isView(source)) {
|
|
1335
|
+
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice();
|
|
1336
|
+
}
|
|
1337
|
+
if (Object.prototype.toString.call(source) === "[object ArrayBuffer]") {
|
|
1338
|
+
return new Uint8Array(source.slice(0));
|
|
1339
|
+
}
|
|
1340
|
+
throw new TypeError("expected an ArrayBuffer or a typed array");
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/governance/intents.ts
|
|
1344
|
+
var LOWERCASE_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
1345
|
+
function assertIdempotencyKey(key) {
|
|
1346
|
+
if (typeof key !== "string" || !LOWERCASE_UUID.test(key)) {
|
|
1347
|
+
throw new TypeError(
|
|
1348
|
+
`idempotency key must be a lowercase UUID (got ${JSON.stringify(key)}); the platform refuses any other form`
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
function newIdempotencyKey() {
|
|
1353
|
+
const c = globalThis.crypto;
|
|
1354
|
+
if (c && typeof c.randomUUID === "function") {
|
|
1355
|
+
return c.randomUUID().toLowerCase();
|
|
1356
|
+
}
|
|
1357
|
+
if (!c || typeof c.getRandomValues !== "function") {
|
|
1358
|
+
throw new Error("no cryptographic random source: pass an idempotency key explicitly");
|
|
1359
|
+
}
|
|
1360
|
+
const b = c.getRandomValues(new Uint8Array(16));
|
|
1361
|
+
b[6] = b[6] & 15 | 64;
|
|
1362
|
+
b[8] = b[8] & 63 | 128;
|
|
1363
|
+
const hex = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
1364
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
1365
|
+
}
|
|
1366
|
+
function nonEmpty(name, value) {
|
|
1367
|
+
if (typeof value !== "string" || value === "") {
|
|
1368
|
+
throw new TypeError(`${name} is required`);
|
|
1369
|
+
}
|
|
1370
|
+
return value;
|
|
1371
|
+
}
|
|
1372
|
+
function keyList(name, keys) {
|
|
1373
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
1374
|
+
throw new TypeError(`${name} must list at least one public key`);
|
|
1375
|
+
}
|
|
1376
|
+
return keys.map((k, i) => {
|
|
1377
|
+
const key = nonEmpty(`${name}[${i}]`, k);
|
|
1378
|
+
if (key.trim() !== key) {
|
|
1379
|
+
throw new TypeError(`${name}[${i}] has leading or trailing whitespace; trim it first`);
|
|
1380
|
+
}
|
|
1381
|
+
return key;
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
function version(v) {
|
|
1385
|
+
if (!Number.isSafeInteger(v) || v < 0) {
|
|
1386
|
+
throw new TypeError(
|
|
1387
|
+
`signer_group_version must be a non-negative integer (got ${String(v)}); read it from the group's \`version\``
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1390
|
+
return v;
|
|
1391
|
+
}
|
|
1392
|
+
function finish(intent) {
|
|
1393
|
+
const canonical = canonicalJSON(intent);
|
|
1394
|
+
return { intent, canonical, bytes: utf8(canonical) };
|
|
1395
|
+
}
|
|
1396
|
+
function addSignersToGroupIntent(params) {
|
|
1397
|
+
assertIdempotencyKey(params.idempotencyKey);
|
|
1398
|
+
return finish({
|
|
1399
|
+
type: "add_signers_to_group",
|
|
1400
|
+
signer_group_id: nonEmpty("signerGroupId", params.signerGroupId),
|
|
1401
|
+
new_member_keys: keyList("newMemberKeys", params.newMemberKeys),
|
|
1402
|
+
signer_group_version: version(params.signerGroupVersion),
|
|
1403
|
+
idempotency_key: params.idempotencyKey
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
function removeSignersFromGroupIntent(params) {
|
|
1407
|
+
assertIdempotencyKey(params.idempotencyKey);
|
|
1408
|
+
return finish({
|
|
1409
|
+
type: "remove_signers_from_group",
|
|
1410
|
+
group_id: nonEmpty("signerGroupId", params.signerGroupId),
|
|
1411
|
+
members_to_remove: keyList("membersToRemove", params.membersToRemove),
|
|
1412
|
+
signer_group_version: version(params.signerGroupVersion),
|
|
1413
|
+
idempotency_key: params.idempotencyKey
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
function updateSignerGroupGovernanceIntent(params) {
|
|
1417
|
+
assertIdempotencyKey(params.idempotencyKey);
|
|
1418
|
+
const intent = {
|
|
1419
|
+
type: "update_signer_group_governance",
|
|
1420
|
+
signer_group_id: nonEmpty("signerGroupId", params.signerGroupId),
|
|
1421
|
+
signer_group_version: version(params.signerGroupVersion),
|
|
1422
|
+
idempotency_key: params.idempotencyKey
|
|
1423
|
+
};
|
|
1424
|
+
if (params.governanceThreshold !== void 0 && params.governanceThreshold !== null) {
|
|
1425
|
+
const t = params.governanceThreshold;
|
|
1426
|
+
if (!Number.isSafeInteger(t) || t < 1 || t > 2147483647) {
|
|
1427
|
+
throw new TypeError(
|
|
1428
|
+
"governanceThreshold must be an integer from 1 to 2^31-1, or null to clear it"
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
intent.governance_threshold = params.governanceThreshold;
|
|
1432
|
+
}
|
|
1433
|
+
if (params.governanceSignerGroupId !== void 0 && params.governanceSignerGroupId !== null) {
|
|
1434
|
+
intent.governance_signer_group_id = nonEmpty(
|
|
1435
|
+
"governanceSignerGroupId",
|
|
1436
|
+
params.governanceSignerGroupId
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
return finish(intent);
|
|
1440
|
+
}
|
|
1441
|
+
function createCryptoDestinationIntent(params) {
|
|
1442
|
+
assertIdempotencyKey(params.idempotencyKey);
|
|
1443
|
+
return finish({
|
|
1444
|
+
type: "create_crypto_destination",
|
|
1445
|
+
recipient_id: nonEmpty("recipientId", params.recipientId),
|
|
1446
|
+
network_id: nonEmpty("networkId", params.networkId),
|
|
1447
|
+
address: nonEmpty("address", params.address),
|
|
1448
|
+
signer_group_id: nonEmpty("signerGroupId", params.signerGroupId),
|
|
1449
|
+
idempotency_key: params.idempotencyKey
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1153
1453
|
// src/client/resources/destinations.ts
|
|
1154
1454
|
var DestinationsResource = class extends BaseResource {
|
|
1155
1455
|
/**
|
|
@@ -1191,6 +1491,15 @@ var DestinationsResource = class extends BaseResource {
|
|
|
1191
1491
|
* ```
|
|
1192
1492
|
*/
|
|
1193
1493
|
async create(recipientId, data, options) {
|
|
1494
|
+
const signatures = data.signatures;
|
|
1495
|
+
if (signatures !== void 0 && signatures.length > 0) {
|
|
1496
|
+
if (!options?.idempotencyKey) {
|
|
1497
|
+
throw new TypeError(
|
|
1498
|
+
"destinations.create with signatures needs options.idempotencyKey: the idempotency_key inside the signed intent (a generated one could never match)"
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
assertIdempotencyKey(options.idempotencyKey);
|
|
1502
|
+
}
|
|
1194
1503
|
return this.transport.request({
|
|
1195
1504
|
method: "POST",
|
|
1196
1505
|
path: `/recipients/${recipientId}/destinations`,
|
|
@@ -1340,11 +1649,18 @@ var AccountsResource = class extends BaseResource {
|
|
|
1340
1649
|
* @param data - Update data
|
|
1341
1650
|
* @returns Updated account
|
|
1342
1651
|
*
|
|
1652
|
+
* Only the developer fee can be updated, and setting one kind replaces the
|
|
1653
|
+
* other. `developer_fee_fixed` is a decimal string in units of the asset
|
|
1654
|
+
* deposited (at most 2 decimals, greater than 0); it applies to future
|
|
1655
|
+
* deposits only.
|
|
1656
|
+
*
|
|
1343
1657
|
* @example
|
|
1344
1658
|
* ```typescript
|
|
1345
1659
|
* const account = await client.accounts.update(accountId, {
|
|
1346
|
-
*
|
|
1660
|
+
* account_type: 'onramp',
|
|
1661
|
+
* developer_fee_fixed: '10.00',
|
|
1347
1662
|
* });
|
|
1663
|
+
* console.log(account.minimum_deposit); // '10.01'
|
|
1348
1664
|
* ```
|
|
1349
1665
|
*/
|
|
1350
1666
|
async update(accountId, data, options) {
|
|
@@ -1683,13 +1999,19 @@ var WalletsResource = class extends BaseResource {
|
|
|
1683
1999
|
* with the wallet's signer-group ECDSA P-256 key, base64-encode the
|
|
1684
2000
|
* DER signature, then post the envelope.
|
|
1685
2001
|
*
|
|
2002
|
+
* Use the SDK's `canonicalJSON`: it matches the platform's canonical form
|
|
2003
|
+
* byte for byte. Write `amount` in its shortest decimal form (`'100'`, not
|
|
2004
|
+
* `'100.00'`; `'0.5'`, not `'0.50'`). The platform parses the amount as a
|
|
2005
|
+
* decimal and re-serializes it before it checks the signature, so trailing
|
|
2006
|
+
* zeros change the signed bytes and the signature fails.
|
|
2007
|
+
*
|
|
1686
2008
|
* @param walletId - Wallet ID
|
|
1687
2009
|
* @param data - Endorsed wallet transaction request: `{ signatures, intent }`
|
|
1688
2010
|
* @returns Created transaction
|
|
1689
2011
|
*
|
|
1690
2012
|
* @example
|
|
1691
2013
|
* ```typescript
|
|
1692
|
-
* import
|
|
2014
|
+
* import { canonicalJSON } from '@dakota-xyz/ts-sdk';
|
|
1693
2015
|
* import { createSign, createPrivateKey, randomUUID } from 'node:crypto';
|
|
1694
2016
|
*
|
|
1695
2017
|
* const intent = {
|
|
@@ -1699,12 +2021,12 @@ var WalletsResource = class extends BaseResource {
|
|
|
1699
2021
|
* kind: 'transfer',
|
|
1700
2022
|
* from: wallet.address,
|
|
1701
2023
|
* to: '0x...',
|
|
1702
|
-
* amount: '100
|
|
2024
|
+
* amount: '100', // shortest decimal form, see below
|
|
1703
2025
|
* asset_id: 'USDC',
|
|
1704
2026
|
* },
|
|
1705
2027
|
* idempotency_key: randomUUID(),
|
|
1706
2028
|
* };
|
|
1707
|
-
* const canonical =
|
|
2029
|
+
* const canonical = canonicalJSON(intent);
|
|
1708
2030
|
* const sig = createSign('SHA256').update(canonical).sign({
|
|
1709
2031
|
* key: createPrivateKey({ key: privateKeyDer, format: 'der', type: 'pkcs8' }),
|
|
1710
2032
|
* dsaEncoding: 'der',
|
|
@@ -2323,6 +2645,63 @@ var PoliciesResource = class extends BaseResource {
|
|
|
2323
2645
|
}
|
|
2324
2646
|
};
|
|
2325
2647
|
|
|
2648
|
+
// src/governance/signer.ts
|
|
2649
|
+
async function signGovernanceIntent(intent, signers) {
|
|
2650
|
+
if (!Array.isArray(signers) || signers.length === 0) {
|
|
2651
|
+
throw new TypeError("a governance change needs at least one signer");
|
|
2652
|
+
}
|
|
2653
|
+
const bytes = ArrayBuffer.isView(intent) ? toBytes(intent) : intent.bytes;
|
|
2654
|
+
const out = [];
|
|
2655
|
+
for (const s of signers) {
|
|
2656
|
+
const sig = typeof s === "function" ? await s(bytes.slice()) : await s.sign(bytes.slice());
|
|
2657
|
+
if (typeof sig !== "string" || sig === "") {
|
|
2658
|
+
throw new Error("a governance signer returned an empty signature");
|
|
2659
|
+
}
|
|
2660
|
+
out.push(sig);
|
|
2661
|
+
}
|
|
2662
|
+
return out;
|
|
2663
|
+
}
|
|
2664
|
+
function webCryptoES256Signer(privateKey, subtle) {
|
|
2665
|
+
return {
|
|
2666
|
+
async sign(payload) {
|
|
2667
|
+
const s = subtle ?? globalThis.crypto?.subtle;
|
|
2668
|
+
if (!s) {
|
|
2669
|
+
throw new Error(
|
|
2670
|
+
"WebCrypto is not available: pass a SubtleCrypto or use ES256Signer on Node"
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
const raw = new Uint8Array(
|
|
2674
|
+
await s.sign(
|
|
2675
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
2676
|
+
privateKey,
|
|
2677
|
+
toArrayBuffer(payload)
|
|
2678
|
+
)
|
|
2679
|
+
);
|
|
2680
|
+
return bytesToBase64(p1363ToDer(raw));
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
function toArrayBuffer(bytes) {
|
|
2685
|
+
const out = new ArrayBuffer(bytes.length);
|
|
2686
|
+
new Uint8Array(out).set(bytes);
|
|
2687
|
+
return out;
|
|
2688
|
+
}
|
|
2689
|
+
function p1363ToDer(sig) {
|
|
2690
|
+
if (sig.length !== 64) {
|
|
2691
|
+
throw new Error(`expected a 64-byte P-256 signature, got ${sig.length} bytes`);
|
|
2692
|
+
}
|
|
2693
|
+
const int = (bytes) => {
|
|
2694
|
+
let i = 0;
|
|
2695
|
+
while (i < bytes.length - 1 && bytes[i] === 0) i++;
|
|
2696
|
+
const trimmed = bytes.slice(i);
|
|
2697
|
+
const body = trimmed[0] & 128 ? Uint8Array.of(0, ...trimmed) : trimmed;
|
|
2698
|
+
return Uint8Array.of(2, body.length, ...body);
|
|
2699
|
+
};
|
|
2700
|
+
const r = int(sig.slice(0, 32));
|
|
2701
|
+
const s = int(sig.slice(32));
|
|
2702
|
+
return Uint8Array.of(48, r.length + s.length, ...r, ...s);
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2326
2705
|
// src/client/resources/signer-groups.ts
|
|
2327
2706
|
var SignerGroupsResource = class extends BaseResource {
|
|
2328
2707
|
/**
|
|
@@ -2371,7 +2750,7 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2371
2750
|
async get(signerGroupId, params) {
|
|
2372
2751
|
return this.transport.request({
|
|
2373
2752
|
method: "GET",
|
|
2374
|
-
path: `/signer-groups/${signerGroupId}`,
|
|
2753
|
+
path: `/signer-groups/${seg(signerGroupId)}`,
|
|
2375
2754
|
query: { ...params }
|
|
2376
2755
|
});
|
|
2377
2756
|
}
|
|
@@ -2382,21 +2761,35 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2382
2761
|
* key of an existing signer resource — not a fresh signer definition.
|
|
2383
2762
|
* Returns the updated group (with the new member included).
|
|
2384
2763
|
*
|
|
2764
|
+
* A governed group (governance settings, or a client with governance
|
|
2765
|
+
* enforcement on) refuses an unsigned add with
|
|
2766
|
+
* `EndorsementRequiredError`; use {@link addSignerSigned} instead, or pass
|
|
2767
|
+
* `signatures` + `signer_group_version` yourself with the SAME idempotency
|
|
2768
|
+
* key that is inside the signed intent.
|
|
2769
|
+
*
|
|
2385
2770
|
* @param signerGroupId - Signer group ID
|
|
2386
2771
|
* @param data - `{ member_key }` (the signer's base64 PKIX public key)
|
|
2387
2772
|
* @returns The updated signer group
|
|
2388
2773
|
*/
|
|
2389
2774
|
async addSigner(signerGroupId, data, options) {
|
|
2775
|
+
if (data.signatures !== void 0) {
|
|
2776
|
+
requireSignedKey("addSigner", options);
|
|
2777
|
+
}
|
|
2390
2778
|
return this.transport.request({
|
|
2391
2779
|
method: "POST",
|
|
2392
|
-
path: `/signer-groups/${signerGroupId}/signers`,
|
|
2780
|
+
path: `/signer-groups/${seg(signerGroupId)}/signers`,
|
|
2393
2781
|
body: data,
|
|
2394
2782
|
idempotencyKey: options?.idempotencyKey,
|
|
2395
2783
|
timeout: options?.timeout
|
|
2396
2784
|
});
|
|
2397
2785
|
}
|
|
2398
2786
|
/**
|
|
2399
|
-
* Remove
|
|
2787
|
+
* Remove ONE signer from a group, unsigned, by its KSUID `signer_id`
|
|
2788
|
+
* (`DELETE /signer-groups/{id}/signers/{signer_id}`).
|
|
2789
|
+
*
|
|
2790
|
+
* A governed group refuses this with `EndorsementRequiredError`; use
|
|
2791
|
+
* {@link removeSignersSigned} instead. Not to be confused with
|
|
2792
|
+
* {@link removeSigners} (plural), the signed removal by PUBLIC KEY.
|
|
2400
2793
|
*
|
|
2401
2794
|
* @param signerGroupId - Signer group ID
|
|
2402
2795
|
* @param signerId - The signer's KSUID `signer_id` — NOT its public key.
|
|
@@ -2407,11 +2800,257 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2407
2800
|
async removeSigner(signerGroupId, signerId, options) {
|
|
2408
2801
|
await this.transport.request({
|
|
2409
2802
|
method: "DELETE",
|
|
2410
|
-
path: `/signer-groups/${signerGroupId}/signers/${signerId}`,
|
|
2803
|
+
path: `/signer-groups/${seg(signerGroupId)}/signers/${seg(signerId)}`,
|
|
2804
|
+
idempotencyKey: options?.idempotencyKey,
|
|
2805
|
+
timeout: options?.timeout
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
// --------------------------------------------------------------------------
|
|
2809
|
+
// Signed (governed) membership and governance changes
|
|
2810
|
+
// --------------------------------------------------------------------------
|
|
2811
|
+
/**
|
|
2812
|
+
* Remove members by PUBLIC KEY, with signatures from the group's governance
|
|
2813
|
+
* (`POST /signer-groups/{id}/signer-removals`). Low level: you supply the
|
|
2814
|
+
* signed body, and `options.idempotencyKey` is required and MUST be the key
|
|
2815
|
+
* inside the signed intent. Prefer {@link removeSignersSigned}. (The
|
|
2816
|
+
* singular {@link removeSigner} is the unsigned removal by `signer_id`.)
|
|
2817
|
+
*/
|
|
2818
|
+
async removeSigners(signerGroupId, data, options) {
|
|
2819
|
+
requireSignedKey("removeSigners", options);
|
|
2820
|
+
return this.transport.request({
|
|
2821
|
+
method: "POST",
|
|
2822
|
+
path: `/signer-groups/${seg(signerGroupId)}/signer-removals`,
|
|
2823
|
+
body: data,
|
|
2824
|
+
idempotencyKey: options?.idempotencyKey,
|
|
2825
|
+
timeout: options?.timeout
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Replace a group's governance settings with signatures from its current
|
|
2830
|
+
* governance (`PATCH /signer-groups/{id}/governance`). The body is the
|
|
2831
|
+
* WHOLE state: a setting left out is cleared. Low level: you supply the
|
|
2832
|
+
* signed body, and `options.idempotencyKey` is required and MUST be the key
|
|
2833
|
+
* inside the signed intent. Prefer {@link updateGovernanceSigned}.
|
|
2834
|
+
*/
|
|
2835
|
+
async updateGovernance(signerGroupId, data, options) {
|
|
2836
|
+
requireSignedKey("updateGovernance", options);
|
|
2837
|
+
return this.transport.request({
|
|
2838
|
+
method: "PATCH",
|
|
2839
|
+
path: `/signer-groups/${seg(signerGroupId)}/governance`,
|
|
2840
|
+
body: data,
|
|
2411
2841
|
idempotencyKey: options?.idempotencyKey,
|
|
2412
2842
|
timeout: options?.timeout
|
|
2413
2843
|
});
|
|
2414
2844
|
}
|
|
2845
|
+
/**
|
|
2846
|
+
* Build (but do not sign or send) the change that adds `memberKey` to the
|
|
2847
|
+
* group. Reads the group's current `version` unless
|
|
2848
|
+
* `options.signerGroupVersion` is given, and generates a lowercase UUID
|
|
2849
|
+
* idempotency key unless one is given.
|
|
2850
|
+
*
|
|
2851
|
+
* Use it when the signatures are collected elsewhere — for example a
|
|
2852
|
+
* passkey in the user's browser: send `change.canonical` there, pass it to
|
|
2853
|
+
* `buildChallenge`, then give the packed assertions to
|
|
2854
|
+
* {@link submitSignedChange}.
|
|
2855
|
+
*/
|
|
2856
|
+
async prepareAddSigner(signerGroupId, memberKey, options) {
|
|
2857
|
+
return this.prepareChange(
|
|
2858
|
+
"add_signers_to_group",
|
|
2859
|
+
signerGroupId,
|
|
2860
|
+
{ memberKeys: [memberKey] },
|
|
2861
|
+
options
|
|
2862
|
+
);
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* Build (but do not sign or send) the change that removes `memberKeys`
|
|
2866
|
+
* (public keys, as the group lists them; signed in this order).
|
|
2867
|
+
*/
|
|
2868
|
+
async prepareRemoveSigners(signerGroupId, memberKeys, options) {
|
|
2869
|
+
return this.prepareChange(
|
|
2870
|
+
"remove_signers_from_group",
|
|
2871
|
+
signerGroupId,
|
|
2872
|
+
{ memberKeys: [...memberKeys] },
|
|
2873
|
+
options
|
|
2874
|
+
);
|
|
2875
|
+
}
|
|
2876
|
+
/**
|
|
2877
|
+
* Build (but do not sign or send) the change that sets the group's
|
|
2878
|
+
* governance to `settings`. It replaces the whole state: a setting left
|
|
2879
|
+
* out or null is cleared.
|
|
2880
|
+
*/
|
|
2881
|
+
async prepareGovernanceUpdate(signerGroupId, settings, options) {
|
|
2882
|
+
const governance = {};
|
|
2883
|
+
if (settings.governance_threshold !== void 0 && settings.governance_threshold !== null) {
|
|
2884
|
+
governance.governance_threshold = settings.governance_threshold;
|
|
2885
|
+
}
|
|
2886
|
+
if (settings.governance_signer_group_id !== void 0 && settings.governance_signer_group_id !== null) {
|
|
2887
|
+
governance.governance_signer_group_id = settings.governance_signer_group_id;
|
|
2888
|
+
}
|
|
2889
|
+
return this.prepareChange(
|
|
2890
|
+
"update_signer_group_governance",
|
|
2891
|
+
signerGroupId,
|
|
2892
|
+
{ governance },
|
|
2893
|
+
options
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Send a prepared change with its signatures (ES256 DER base64, or packed
|
|
2898
|
+
* passkey assertions), using the change's idempotency key as
|
|
2899
|
+
* `X-Idempotency-Key`. Re-checks that the change still matches the intent
|
|
2900
|
+
* that was signed and refuses it otherwise, without sending anything.
|
|
2901
|
+
*
|
|
2902
|
+
* @throws EndorsementRequiredError, InsufficientEndorsementsError,
|
|
2903
|
+
* StaleSignerGroupVersionError, BelowThresholdError (all APIError)
|
|
2904
|
+
*/
|
|
2905
|
+
async submitSignedChange(change, signatures, options) {
|
|
2906
|
+
if (!Array.isArray(signatures) || signatures.length === 0 || signatures.some((s) => typeof s !== "string" || s === "")) {
|
|
2907
|
+
throw new TypeError("a signed change needs at least one non-empty signature");
|
|
2908
|
+
}
|
|
2909
|
+
const built = buildChangeIntent(change);
|
|
2910
|
+
if (built.canonical !== change.canonical) {
|
|
2911
|
+
throw new Error(
|
|
2912
|
+
"the prepared change does not match the intent that was signed (it was altered after it was prepared); prepare it again"
|
|
2913
|
+
);
|
|
2914
|
+
}
|
|
2915
|
+
const i = built.intent;
|
|
2916
|
+
const requestOptions = { idempotencyKey: i.idempotency_key, timeout: options?.timeout };
|
|
2917
|
+
const sigs = [...signatures];
|
|
2918
|
+
switch (i.type) {
|
|
2919
|
+
case "add_signers_to_group":
|
|
2920
|
+
return this.addSigner(
|
|
2921
|
+
i.signer_group_id,
|
|
2922
|
+
{
|
|
2923
|
+
member_key: i.new_member_keys[0],
|
|
2924
|
+
signer_group_version: i.signer_group_version,
|
|
2925
|
+
signatures: sigs
|
|
2926
|
+
},
|
|
2927
|
+
requestOptions
|
|
2928
|
+
);
|
|
2929
|
+
case "remove_signers_from_group":
|
|
2930
|
+
return this.removeSigners(
|
|
2931
|
+
i.group_id,
|
|
2932
|
+
{
|
|
2933
|
+
members_to_remove: [...i.members_to_remove],
|
|
2934
|
+
signer_group_version: i.signer_group_version,
|
|
2935
|
+
signatures: sigs
|
|
2936
|
+
},
|
|
2937
|
+
requestOptions
|
|
2938
|
+
);
|
|
2939
|
+
case "update_signer_group_governance": {
|
|
2940
|
+
const body = {
|
|
2941
|
+
...i.governance_threshold !== void 0 && {
|
|
2942
|
+
governance_threshold: i.governance_threshold
|
|
2943
|
+
},
|
|
2944
|
+
...i.governance_signer_group_id !== void 0 && {
|
|
2945
|
+
governance_signer_group_id: i.governance_signer_group_id
|
|
2946
|
+
},
|
|
2947
|
+
signer_group_version: i.signer_group_version,
|
|
2948
|
+
signatures: sigs
|
|
2949
|
+
};
|
|
2950
|
+
return this.updateGovernance(i.signer_group_id, body, requestOptions);
|
|
2951
|
+
}
|
|
2952
|
+
default:
|
|
2953
|
+
throw new TypeError(`cannot submit a ${i.type} change from signerGroups`);
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* Add `memberKey` to a governed group in one call: read the version, build
|
|
2958
|
+
* the `add_signers_to_group` intent, sign it with each signer (in order),
|
|
2959
|
+
* and send it with the same idempotency key in the intent and the header.
|
|
2960
|
+
*
|
|
2961
|
+
* @param signers - ES256 signers (`ES256Signer`, your KMS) or plain
|
|
2962
|
+
* `(bytes) => signature` functions; together they must meet the group's
|
|
2963
|
+
* `effective_governance_threshold`. For a passkey in the user's browser
|
|
2964
|
+
* or app, use {@link prepareAddSigner} + {@link submitSignedChange}
|
|
2965
|
+
* instead, so the API key stays on your server; `webauthnSigner` fits
|
|
2966
|
+
* here only when the passkey prompt runs in the same process as this
|
|
2967
|
+
* client. Each stale retry calls every signer again.
|
|
2968
|
+
* @example
|
|
2969
|
+
* ```typescript
|
|
2970
|
+
* const group = await client.signerGroups.addSignerSigned(groupId, newKey, [
|
|
2971
|
+
* ES256Signer.fromPrivateKey(adminKeyPem),
|
|
2972
|
+
* ]);
|
|
2973
|
+
* ```
|
|
2974
|
+
*/
|
|
2975
|
+
async addSignerSigned(signerGroupId, memberKey, signers, options) {
|
|
2976
|
+
return this.signAndSubmit(
|
|
2977
|
+
() => this.prepareAddSigner(signerGroupId, memberKey, options),
|
|
2978
|
+
signers,
|
|
2979
|
+
options
|
|
2980
|
+
);
|
|
2981
|
+
}
|
|
2982
|
+
/** Remove `memberKeys` from a governed group in one call; see {@link addSignerSigned}. */
|
|
2983
|
+
async removeSignersSigned(signerGroupId, memberKeys, signers, options) {
|
|
2984
|
+
return this.signAndSubmit(
|
|
2985
|
+
() => this.prepareRemoveSigners(signerGroupId, memberKeys, options),
|
|
2986
|
+
signers,
|
|
2987
|
+
options
|
|
2988
|
+
);
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* Replace a group's governance settings in one call; see
|
|
2992
|
+
* {@link addSignerSigned}. Signed by the group's CURRENT governance.
|
|
2993
|
+
*
|
|
2994
|
+
* `staleRetries` is refused here: the change replaces the WHOLE governance
|
|
2995
|
+
* state, so re-signing it after someone else changed the group would
|
|
2996
|
+
* silently undo their change. On `StaleSignerGroupVersionError`, re-read
|
|
2997
|
+
* the group, decide, and call again.
|
|
2998
|
+
*/
|
|
2999
|
+
async updateGovernanceSigned(signerGroupId, settings, signers, options) {
|
|
3000
|
+
if (options?.staleRetries) {
|
|
3001
|
+
throw new TypeError(
|
|
3002
|
+
"staleRetries is not supported on updateGovernanceSigned: a re-sign after a concurrent change would undo it"
|
|
3003
|
+
);
|
|
3004
|
+
}
|
|
3005
|
+
return this.signAndSubmit(
|
|
3006
|
+
() => this.prepareGovernanceUpdate(signerGroupId, settings, options),
|
|
3007
|
+
signers,
|
|
3008
|
+
options
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
3011
|
+
async prepareChange(kind, signerGroupId, fields, options) {
|
|
3012
|
+
if (options?.idempotencyKey !== void 0) {
|
|
3013
|
+
assertIdempotencyKey(options.idempotencyKey);
|
|
3014
|
+
}
|
|
3015
|
+
const signerGroupVersion = options?.signerGroupVersion ?? await this.currentVersion(signerGroupId);
|
|
3016
|
+
const draft = {
|
|
3017
|
+
kind,
|
|
3018
|
+
signerGroupId,
|
|
3019
|
+
signerGroupVersion,
|
|
3020
|
+
idempotencyKey: options?.idempotencyKey ?? governanceIdempotencyKey(),
|
|
3021
|
+
...fields,
|
|
3022
|
+
canonical: ""
|
|
3023
|
+
};
|
|
3024
|
+
return { ...draft, canonical: buildChangeIntent(draft).canonical };
|
|
3025
|
+
}
|
|
3026
|
+
async currentVersion(signerGroupId) {
|
|
3027
|
+
const group = await this.get(signerGroupId);
|
|
3028
|
+
if (typeof group.version !== "number") {
|
|
3029
|
+
throw new Error(
|
|
3030
|
+
`signer group ${signerGroupId} has no version in the response, so a signed change cannot be built; pass signerGroupVersion if you know it`
|
|
3031
|
+
);
|
|
3032
|
+
}
|
|
3033
|
+
return group.version;
|
|
3034
|
+
}
|
|
3035
|
+
async signAndSubmit(prepare, signers, options) {
|
|
3036
|
+
if (!Array.isArray(signers) || signers.length === 0) {
|
|
3037
|
+
throw new TypeError("a governance change needs at least one signer");
|
|
3038
|
+
}
|
|
3039
|
+
let retries = staleRetryBudget(options);
|
|
3040
|
+
for (; ; ) {
|
|
3041
|
+
const change = await prepare();
|
|
3042
|
+
const signatures = await signGovernanceIntent(utf8(change.canonical), signers);
|
|
3043
|
+
try {
|
|
3044
|
+
return await this.submitSignedChange(change, signatures, { timeout: options?.timeout });
|
|
3045
|
+
} catch (err) {
|
|
3046
|
+
if (err instanceof StaleSignerGroupVersionError && retries > 0) {
|
|
3047
|
+
retries--;
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
throw err;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
2415
3054
|
/**
|
|
2416
3055
|
* Get wallets attached to a signer group.
|
|
2417
3056
|
*
|
|
@@ -2423,7 +3062,7 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2423
3062
|
async getWallets(signerGroupId) {
|
|
2424
3063
|
return this.transport.request({
|
|
2425
3064
|
method: "GET",
|
|
2426
|
-
path: `/signer-groups/${signerGroupId}/wallets`
|
|
3065
|
+
path: `/signer-groups/${seg(signerGroupId)}/wallets`
|
|
2427
3066
|
});
|
|
2428
3067
|
}
|
|
2429
3068
|
/**
|
|
@@ -2440,7 +3079,7 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2440
3079
|
async attachToWallet(walletId, signerGroupId, options) {
|
|
2441
3080
|
await this.transport.request({
|
|
2442
3081
|
method: "PUT",
|
|
2443
|
-
path: `/wallets/${walletId}/signer-groups/${signerGroupId}`,
|
|
3082
|
+
path: `/wallets/${seg(walletId)}/signer-groups/${seg(signerGroupId)}`,
|
|
2444
3083
|
body: options?.endorsement,
|
|
2445
3084
|
idempotencyKey: options?.idempotencyKey,
|
|
2446
3085
|
timeout: options?.timeout
|
|
@@ -2460,7 +3099,7 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2460
3099
|
async detachFromWallet(walletId, signerGroupId, options) {
|
|
2461
3100
|
await this.transport.request({
|
|
2462
3101
|
method: "DELETE",
|
|
2463
|
-
path: `/wallets/${walletId}/signer-groups/${signerGroupId}`,
|
|
3102
|
+
path: `/wallets/${seg(walletId)}/signer-groups/${seg(signerGroupId)}`,
|
|
2464
3103
|
body: options?.endorsement,
|
|
2465
3104
|
idempotencyKey: options?.idempotencyKey,
|
|
2466
3105
|
timeout: options?.timeout
|
|
@@ -2477,6 +3116,65 @@ var SignerGroupsResource = class extends BaseResource {
|
|
|
2477
3116
|
return this.paginate(`/wallets/${walletId}/signer-groups`, params);
|
|
2478
3117
|
}
|
|
2479
3118
|
};
|
|
3119
|
+
function seg(id) {
|
|
3120
|
+
if (typeof id !== "string" || id === "" || id === "." || id === "..") {
|
|
3121
|
+
throw new TypeError(`invalid id for a request path: ${JSON.stringify(id)}`);
|
|
3122
|
+
}
|
|
3123
|
+
return encodeURIComponent(id);
|
|
3124
|
+
}
|
|
3125
|
+
var MAX_STALE_RETRIES = 5;
|
|
3126
|
+
function staleRetryBudget(options) {
|
|
3127
|
+
const n = options?.staleRetries ?? 0;
|
|
3128
|
+
if (!Number.isInteger(n) || n < 0 || n > MAX_STALE_RETRIES) {
|
|
3129
|
+
throw new TypeError(`staleRetries must be an integer from 0 to ${MAX_STALE_RETRIES}`);
|
|
3130
|
+
}
|
|
3131
|
+
if (n > 0 && (options?.signerGroupVersion !== void 0 || options?.idempotencyKey !== void 0)) {
|
|
3132
|
+
throw new TypeError(
|
|
3133
|
+
"staleRetries cannot be combined with a fixed signerGroupVersion or idempotencyKey: a retry needs a fresh read and a fresh key"
|
|
3134
|
+
);
|
|
3135
|
+
}
|
|
3136
|
+
return n;
|
|
3137
|
+
}
|
|
3138
|
+
function governanceIdempotencyKey() {
|
|
3139
|
+
const c = globalThis.crypto;
|
|
3140
|
+
return typeof c?.randomUUID === "function" ? newIdempotencyKey() : randomUUID().toLowerCase();
|
|
3141
|
+
}
|
|
3142
|
+
function requireSignedKey(method, options) {
|
|
3143
|
+
if (!options?.idempotencyKey) {
|
|
3144
|
+
throw new TypeError(
|
|
3145
|
+
`${method} with signatures needs options.idempotencyKey: the idempotency_key inside the signed intent (a generated one could never match)`
|
|
3146
|
+
);
|
|
3147
|
+
}
|
|
3148
|
+
assertIdempotencyKey(options.idempotencyKey);
|
|
3149
|
+
}
|
|
3150
|
+
function buildChangeIntent(change) {
|
|
3151
|
+
const common = {
|
|
3152
|
+
signerGroupId: change.signerGroupId,
|
|
3153
|
+
signerGroupVersion: change.signerGroupVersion,
|
|
3154
|
+
idempotencyKey: change.idempotencyKey
|
|
3155
|
+
};
|
|
3156
|
+
switch (change.kind) {
|
|
3157
|
+
case "add_signers_to_group":
|
|
3158
|
+
if (!change.memberKeys || change.memberKeys.length !== 1) {
|
|
3159
|
+
throw new TypeError(
|
|
3160
|
+
"an add change carries exactly one member key (the endpoint adds one per request)"
|
|
3161
|
+
);
|
|
3162
|
+
}
|
|
3163
|
+
return addSignersToGroupIntent({ ...common, newMemberKeys: change.memberKeys });
|
|
3164
|
+
case "remove_signers_from_group":
|
|
3165
|
+
return removeSignersFromGroupIntent({ ...common, membersToRemove: change.memberKeys ?? [] });
|
|
3166
|
+
case "update_signer_group_governance":
|
|
3167
|
+
return updateSignerGroupGovernanceIntent({
|
|
3168
|
+
...common,
|
|
3169
|
+
governanceThreshold: change.governance?.governance_threshold,
|
|
3170
|
+
governanceSignerGroupId: change.governance?.governance_signer_group_id
|
|
3171
|
+
});
|
|
3172
|
+
default:
|
|
3173
|
+
throw new TypeError(
|
|
3174
|
+
`unknown signer-group change kind ${JSON.stringify(change.kind)}`
|
|
3175
|
+
);
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
2480
3178
|
var SignersResource = class extends BaseResource {
|
|
2481
3179
|
/**
|
|
2482
3180
|
* Create a new signer.
|
|
@@ -2535,6 +3233,23 @@ var ApiKeysResource = class extends BaseResource {
|
|
|
2535
3233
|
list(params) {
|
|
2536
3234
|
return this.paginate("/api-keys", params);
|
|
2537
3235
|
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Change the name, the scope, or both, of an API key. A new scope applies
|
|
3238
|
+
* from the next request made with the key. The key value does not change.
|
|
3239
|
+
*
|
|
3240
|
+
* @param apiKeyId - API key ID
|
|
3241
|
+
* @param data - The new name, the new scope, or both
|
|
3242
|
+
* @returns The updated API key
|
|
3243
|
+
*/
|
|
3244
|
+
async update(apiKeyId, data, options) {
|
|
3245
|
+
return this.transport.request({
|
|
3246
|
+
method: "PATCH",
|
|
3247
|
+
path: `/api-keys/${apiKeyId}`,
|
|
3248
|
+
body: data,
|
|
3249
|
+
idempotencyKey: options?.idempotencyKey,
|
|
3250
|
+
timeout: options?.timeout
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
2538
3253
|
/**
|
|
2539
3254
|
* Delete an API key.
|
|
2540
3255
|
*
|
|
@@ -2859,11 +3574,11 @@ var LegalResource = class extends BaseResource {
|
|
|
2859
3574
|
* });
|
|
2860
3575
|
* ```
|
|
2861
3576
|
*/
|
|
2862
|
-
async get(documentKey,
|
|
3577
|
+
async get(documentKey, version2) {
|
|
2863
3578
|
return this.transport.request({
|
|
2864
3579
|
method: "GET",
|
|
2865
3580
|
path: `/legal/documents/${documentKey}`,
|
|
2866
|
-
query:
|
|
3581
|
+
query: version2 !== void 0 ? { version: version2 } : void 0
|
|
2867
3582
|
});
|
|
2868
3583
|
}
|
|
2869
3584
|
};
|
|
@@ -2929,6 +3644,65 @@ var RDMarketingFeeResource = class extends BaseResource {
|
|
|
2929
3644
|
path: `/rd-marketing-fee/statements/${month}`
|
|
2930
3645
|
});
|
|
2931
3646
|
}
|
|
3647
|
+
/**
|
|
3648
|
+
* The wallet this client's RD marketing fee is sent to.
|
|
3649
|
+
*
|
|
3650
|
+
* A **404** here is the ordinary state for a client who has not registered
|
|
3651
|
+
* one yet — not an error. A **403** means the client is not in the
|
|
3652
|
+
* programme at all.
|
|
3653
|
+
*
|
|
3654
|
+
* @returns The registered destination: always on Base (`eip155:8453`)
|
|
3655
|
+
*
|
|
3656
|
+
* @example
|
|
3657
|
+
* ```typescript
|
|
3658
|
+
* try {
|
|
3659
|
+
* const dest = await client.rdMarketingFee.getPayoutDestination();
|
|
3660
|
+
* console.log(dest.address);
|
|
3661
|
+
* } catch (error) {
|
|
3662
|
+
* if (error instanceof APIError && error.statusCode === 404) {
|
|
3663
|
+
* // Nothing registered yet — prompt for one.
|
|
3664
|
+
* }
|
|
3665
|
+
* }
|
|
3666
|
+
* ```
|
|
3667
|
+
*/
|
|
3668
|
+
async getPayoutDestination() {
|
|
3669
|
+
return this.transport.request({
|
|
3670
|
+
method: "GET",
|
|
3671
|
+
path: "/rd-marketing-fee/payout-destination"
|
|
3672
|
+
});
|
|
3673
|
+
}
|
|
3674
|
+
/**
|
|
3675
|
+
* Register, or replace, the wallet the RD marketing fee is sent to.
|
|
3676
|
+
*
|
|
3677
|
+
* RD exists only on Base, so the chain is not a parameter — only an EVM
|
|
3678
|
+
* `address`. There is one destination per client, so this REPLACES any
|
|
3679
|
+
* existing one. Emits `rd_payout_destination.updated`.
|
|
3680
|
+
*
|
|
3681
|
+
* This is a SEPARATE registration from the developer-fee payout
|
|
3682
|
+
* destination (`client.feePayoutDestination`): the two programmes pay
|
|
3683
|
+
* different assets and are set independently.
|
|
3684
|
+
*
|
|
3685
|
+
* @param data - The EVM address on Base to pay the fee to
|
|
3686
|
+
* @param options - Request options (e.g., custom idempotency key)
|
|
3687
|
+
* @returns The stored destination
|
|
3688
|
+
*
|
|
3689
|
+
* @example
|
|
3690
|
+
* ```typescript
|
|
3691
|
+
* const dest = await client.rdMarketingFee.setPayoutDestination({
|
|
3692
|
+
* address: '0x1234567890123456789012345678901234567890',
|
|
3693
|
+
* });
|
|
3694
|
+
* console.log(dest.chain); // 'eip155:8453'
|
|
3695
|
+
* ```
|
|
3696
|
+
*/
|
|
3697
|
+
async setPayoutDestination(data, options) {
|
|
3698
|
+
return this.transport.request({
|
|
3699
|
+
method: "PUT",
|
|
3700
|
+
path: "/rd-marketing-fee/payout-destination",
|
|
3701
|
+
body: data,
|
|
3702
|
+
idempotencyKey: options?.idempotencyKey,
|
|
3703
|
+
timeout: options?.timeout
|
|
3704
|
+
});
|
|
3705
|
+
}
|
|
2932
3706
|
};
|
|
2933
3707
|
|
|
2934
3708
|
// src/client/resources/sandbox.ts
|
|
@@ -2941,9 +3715,13 @@ var SandboxResource = class extends BaseResource {
|
|
|
2941
3715
|
*
|
|
2942
3716
|
* | Type | Required Fields |
|
|
2943
3717
|
* |------|-----------------|
|
|
2944
|
-
* | `ach_inbound`, `
|
|
2945
|
-
* | `crypto_inbound` | `
|
|
2946
|
-
* | `*_outbound_*`, `*_reversal` | `
|
|
3718
|
+
* | `ach_inbound`, `fedwire_inbound`, `swift_inbound`, `fednow_inbound` | `account_id` |
|
|
3719
|
+
* | `crypto_inbound` | `wallet_address` |
|
|
3720
|
+
* | `*_outbound_*`, `*_reversal` | `account_id` + `one_off_transaction_id` |
|
|
3721
|
+
*
|
|
3722
|
+
* `swift_inbound` and `fedwire_inbound` behave identically: the rail a
|
|
3723
|
+
* deposit books on is derived from the RECEIVING account, so pick the
|
|
3724
|
+
* account, not the type, to choose between a SWIFT and a Fedwire deposit.
|
|
2947
3725
|
*
|
|
2948
3726
|
* @param data - Simulation request data
|
|
2949
3727
|
* @returns Simulation response with ID and state
|
|
@@ -2972,11 +3750,13 @@ var SandboxResource = class extends BaseResource {
|
|
|
2972
3750
|
* destination_payment_rail: 'ach',
|
|
2973
3751
|
* });
|
|
2974
3752
|
*
|
|
2975
|
-
* // Simulate the ACH settlement
|
|
3753
|
+
* // Simulate the ACH settlement. `account_id` is the offramp account that
|
|
3754
|
+
* // funded the transaction.
|
|
2976
3755
|
* await client.sandbox.simulateInbound({
|
|
2977
3756
|
* simulation_id: `sim_${Date.now()}`,
|
|
2978
3757
|
* type: 'ach_outbound_settled',
|
|
2979
|
-
*
|
|
3758
|
+
* account_id: 'acc_456',
|
|
3759
|
+
* one_off_transaction_id: tx.id,
|
|
2980
3760
|
* amount: '100.00',
|
|
2981
3761
|
* currency: 'USD',
|
|
2982
3762
|
* });
|
|
@@ -2987,7 +3767,7 @@ var SandboxResource = class extends BaseResource {
|
|
|
2987
3767
|
* const result = await client.sandbox.simulateInbound({
|
|
2988
3768
|
* simulation_id: `sim_${Date.now()}`,
|
|
2989
3769
|
* type: 'crypto_inbound',
|
|
2990
|
-
*
|
|
3770
|
+
* wallet_address: '0x165cd37b4c644c2921454429e7f9358d18a45e14',
|
|
2991
3771
|
* amount: '500.00',
|
|
2992
3772
|
* currency: 'USDC',
|
|
2993
3773
|
* });
|
|
@@ -3016,21 +3796,16 @@ var SandboxResource = class extends BaseResource {
|
|
|
3016
3796
|
* @param data - Simulation request data
|
|
3017
3797
|
* @returns Simulation response with previous and new state
|
|
3018
3798
|
*
|
|
3019
|
-
*
|
|
3799
|
+
* `applicant_activate` runs the same code path as `kyb_approve`. One call
|
|
3800
|
+
* is enough: do not send `applicant_activate` after `kyb_approve`.
|
|
3801
|
+
*
|
|
3802
|
+
* @example Approve an application
|
|
3020
3803
|
* ```typescript
|
|
3021
|
-
* // Step 1: Approve the KYB application
|
|
3022
3804
|
* await client.sandbox.simulateOnboarding({
|
|
3023
3805
|
* type: 'kyb_approve',
|
|
3024
3806
|
* applicant_id: customer.application_id,
|
|
3025
3807
|
* simulation_id: `sim_kyb_${Date.now()}`,
|
|
3026
3808
|
* });
|
|
3027
|
-
*
|
|
3028
|
-
* // Step 2: Activate the applicant (triggers provisioning)
|
|
3029
|
-
* await client.sandbox.simulateOnboarding({
|
|
3030
|
-
* type: 'applicant_activate',
|
|
3031
|
-
* applicant_id: customer.application_id,
|
|
3032
|
-
* simulation_id: `sim_activate_${Date.now()}`,
|
|
3033
|
-
* });
|
|
3034
3809
|
* ```
|
|
3035
3810
|
*
|
|
3036
3811
|
* @example Reject a KYB application
|
|
@@ -3467,14 +4242,22 @@ var InstructionsResource = class extends BaseResource {
|
|
|
3467
4242
|
*
|
|
3468
4243
|
* One optional field shapes the actuation:
|
|
3469
4244
|
*
|
|
3470
|
-
* - `
|
|
3471
|
-
* crypto payout, `
|
|
3472
|
-
*
|
|
3473
|
-
*
|
|
3474
|
-
*
|
|
3475
|
-
*
|
|
3476
|
-
*
|
|
3477
|
-
*
|
|
4245
|
+
* - `developer_fee_defaults` declares your fee PER PAYOUT TYPE —
|
|
4246
|
+
* `swap` for a crypto payout, `offramp` for a bank payout — each as
|
|
4247
|
+
* a percentage (`developer_fee_bps`) or a flat amount per payment
|
|
4248
|
+
* (`developer_fee_fixed`, a decimal string in units of the asset
|
|
4249
|
+
* deposited, added on top of the amount), never both. They are
|
|
4250
|
+
* independent, so one conversation can charge a swap and stay silent
|
|
4251
|
+
* about a bank payout in the same turn. Omit a payout type (or set its
|
|
4252
|
+
* `developer_fee_bps` to zero) and it carries no fee: nothing is
|
|
4253
|
+
* charged, nothing is added to the amount, and the agent is told
|
|
4254
|
+
* nothing about a fee it could mention. Both are
|
|
4255
|
+
* DEFAULTS for the auto-accounts this request creates — an action-level
|
|
4256
|
+
* `developer_fee_bps` or `developer_fee_fixed` still wins outright.
|
|
4257
|
+
*
|
|
4258
|
+
* It replaces the deprecated `developer_fee` (`swap_bps` /
|
|
4259
|
+
* `offramp_bps`), which the platform still accepts. Send one or the
|
|
4260
|
+
* other: both is a 400.
|
|
3478
4261
|
*
|
|
3479
4262
|
* The vocabulary the actuation is judged against comes from the policy
|
|
3480
4263
|
* registered with `client.agenticPolicy.set()` — the same one the drafting
|
|
@@ -3667,11 +4450,17 @@ var MandatesResource = class extends BaseResource {
|
|
|
3667
4450
|
* it at its due date, days later, with the payee unpaid.
|
|
3668
4451
|
*
|
|
3669
4452
|
* Advisory — nothing here reserves budget, and the gate remains the
|
|
3670
|
-
* authority at fire time.
|
|
3671
|
-
*
|
|
3672
|
-
*
|
|
3673
|
-
*
|
|
3674
|
-
*
|
|
4453
|
+
* authority at fire time. Three things to honour when reading a line:
|
|
4454
|
+
*
|
|
4455
|
+
* - An ABSENT `remaining_amount` / `remaining_count` means "not capped",
|
|
4456
|
+
* never "nothing left" — EXCEPT on a `per_target` line with
|
|
4457
|
+
* `prior_scope: true`. That line's spend was booked under an earlier
|
|
4458
|
+
* version's target scope (before a `target_type` amendment) and no
|
|
4459
|
+
* current target claims it: the spend is real and still counts toward
|
|
4460
|
+
* the aggregate caps, but no payment can consume the bucket, so absent
|
|
4461
|
+
* remaining_* there means NO headroom. Never set on aggregate lines.
|
|
4462
|
+
* - A `remaining_amount` of `'?'` means the figure could not be summed and
|
|
4463
|
+
* MUST be treated as no headroom (the gate fails closed on the same data).
|
|
3675
4464
|
*
|
|
3676
4465
|
* @param mandateId - Mandate ID
|
|
3677
4466
|
* @returns Per-target and aggregate budget lines, as of a stated instant
|
|
@@ -3679,8 +4468,11 @@ var MandatesResource = class extends BaseResource {
|
|
|
3679
4468
|
* @example
|
|
3680
4469
|
* ```typescript
|
|
3681
4470
|
* const budget = await client.mandates.getBudget(mandateId);
|
|
3682
|
-
* for (const line of budget.aggregate) {
|
|
3683
|
-
*
|
|
4471
|
+
* for (const line of [...budget.per_target, ...budget.aggregate]) {
|
|
4472
|
+
* const headroom = line.prior_scope
|
|
4473
|
+
* ? 'none (prior scope)'
|
|
4474
|
+
* : (line.remaining_amount ?? 'uncapped');
|
|
4475
|
+
* console.log(line.target ?? '(all payees)', line.bucket, headroom);
|
|
3684
4476
|
* }
|
|
3685
4477
|
* ```
|
|
3686
4478
|
*/
|
|
@@ -3767,6 +4559,47 @@ var InsightsResource = class extends BaseResource {
|
|
|
3767
4559
|
path: `/customers/${customerId}/insights`
|
|
3768
4560
|
});
|
|
3769
4561
|
}
|
|
4562
|
+
/**
|
|
4563
|
+
* Get the client-level portfolio insight report.
|
|
4564
|
+
*
|
|
4565
|
+
* The client-scope companion of {@link get}: one deterministic, read-only
|
|
4566
|
+
* report over ALL of the caller's customers' agentic activity. Items reuse
|
|
4567
|
+
* the customer report's shape, plus `customer_id` (omitted on
|
|
4568
|
+
* cross-customer aggregates) and `responsibility` (a grouping label for
|
|
4569
|
+
* filtering — not ownership). On top of the items the report carries
|
|
4570
|
+
* dashboard-shaped data: KPI `metrics` with previous-window values for
|
|
4571
|
+
* trend deltas, daily `series` for charts, and a per-customer roll-up in
|
|
4572
|
+
* `customers` sorted worst-first.
|
|
4573
|
+
*
|
|
4574
|
+
* Every filter is optional and only NARROWS the report; the response shape
|
|
4575
|
+
* never changes. The report scans at most 100 customers per request —
|
|
4576
|
+
* `snapshot.customers.scanned < total` says it was computed over a prefix
|
|
4577
|
+
* of the book, never silently.
|
|
4578
|
+
*
|
|
4579
|
+
* A 404 means agentic payments are not enabled for the key, or the
|
|
4580
|
+
* `customer_id` filter names an unknown customer.
|
|
4581
|
+
*
|
|
4582
|
+
* @param params - Optional filters and the report window
|
|
4583
|
+
* @returns The client's portfolio insight report
|
|
4584
|
+
*
|
|
4585
|
+
* @example
|
|
4586
|
+
* ```typescript
|
|
4587
|
+
* const report = await client.insights.getClientReport({
|
|
4588
|
+
* severity: 'critical,warn',
|
|
4589
|
+
* window_days: 30,
|
|
4590
|
+
* });
|
|
4591
|
+
* for (const row of report.customers) {
|
|
4592
|
+
* if (row.item_counts.critical > 0) console.log(row.customer_id, row.name);
|
|
4593
|
+
* }
|
|
4594
|
+
* ```
|
|
4595
|
+
*/
|
|
4596
|
+
async getClientReport(params) {
|
|
4597
|
+
return this.transport.request({
|
|
4598
|
+
method: "GET",
|
|
4599
|
+
path: "/insights",
|
|
4600
|
+
query: { ...params }
|
|
4601
|
+
});
|
|
4602
|
+
}
|
|
3770
4603
|
};
|
|
3771
4604
|
|
|
3772
4605
|
// src/client/resources/agentic-policy.ts
|
|
@@ -3852,6 +4685,7 @@ var AgentConversation = class {
|
|
|
3852
4685
|
paymentAgentId;
|
|
3853
4686
|
timezone;
|
|
3854
4687
|
timeout;
|
|
4688
|
+
developerFeeDefaults;
|
|
3855
4689
|
developerFee;
|
|
3856
4690
|
history = [];
|
|
3857
4691
|
constructor(client, paymentAgentId, history, options) {
|
|
@@ -3859,6 +4693,7 @@ var AgentConversation = class {
|
|
|
3859
4693
|
this.paymentAgentId = paymentAgentId;
|
|
3860
4694
|
this.timezone = options?.timezone;
|
|
3861
4695
|
this.timeout = options?.timeout;
|
|
4696
|
+
this.developerFeeDefaults = options?.developerFeeDefaults;
|
|
3862
4697
|
this.developerFee = options?.developerFee;
|
|
3863
4698
|
if (history && history.length > 0) {
|
|
3864
4699
|
this.history = history.map(cloneMessage);
|
|
@@ -3907,6 +4742,7 @@ var AgentConversation = class {
|
|
|
3907
4742
|
// Resent on EVERY turn — the endpoint is stateless, so a value
|
|
3908
4743
|
// given once would be forgotten on the next one.
|
|
3909
4744
|
...this.timezone ? { timezone: this.timezone } : {},
|
|
4745
|
+
...this.developerFeeDefaults ? { developer_fee_defaults: this.developerFeeDefaults } : {},
|
|
3910
4746
|
...this.developerFee ? { developer_fee: this.developerFee } : {}
|
|
3911
4747
|
},
|
|
3912
4748
|
this.timeout !== void 0 ? { timeout: this.timeout } : void 0
|
|
@@ -4193,41 +5029,84 @@ var DakotaClient = class {
|
|
|
4193
5029
|
return this.config.baseURL;
|
|
4194
5030
|
}
|
|
4195
5031
|
};
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
if (value === null || value === void 0) {
|
|
4203
|
-
return "null";
|
|
5032
|
+
var ES256Signer = class _ES256Signer {
|
|
5033
|
+
privateKey;
|
|
5034
|
+
publicKey;
|
|
5035
|
+
constructor(privateKey, publicKey) {
|
|
5036
|
+
this.privateKey = privateKey;
|
|
5037
|
+
this.publicKey = publicKey;
|
|
4204
5038
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
5039
|
+
/**
|
|
5040
|
+
* Generate a fresh P-256 keypair.
|
|
5041
|
+
*/
|
|
5042
|
+
static generate() {
|
|
5043
|
+
const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
5044
|
+
return new _ES256Signer(privateKey, publicKey);
|
|
4207
5045
|
}
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
5046
|
+
/**
|
|
5047
|
+
* Adopt an existing P-256 private key. Accepts a PKCS#8 PEM string, a
|
|
5048
|
+
* DER-encoded PKCS#8 buffer, or a Node {@link KeyObject}.
|
|
5049
|
+
*/
|
|
5050
|
+
static fromPrivateKey(key) {
|
|
5051
|
+
const privateKey = typeof key === "string" || key instanceof Uint8Array ? createPrivateKey({
|
|
5052
|
+
key,
|
|
5053
|
+
format: typeof key === "string" ? "pem" : "der",
|
|
5054
|
+
type: "pkcs8"
|
|
5055
|
+
}) : key;
|
|
5056
|
+
if (privateKey.asymmetricKeyType !== "ec") {
|
|
5057
|
+
throw new Error("a P-256 private key is required (ES256)");
|
|
4211
5058
|
}
|
|
4212
|
-
|
|
5059
|
+
const details = privateKey.asymmetricKeyDetails;
|
|
5060
|
+
if (details?.namedCurve !== "prime256v1") {
|
|
5061
|
+
throw new Error("a P-256 private key is required (ES256)");
|
|
5062
|
+
}
|
|
5063
|
+
const publicKey = createPublicKey(privateKey);
|
|
5064
|
+
return new _ES256Signer(privateKey, publicKey);
|
|
4213
5065
|
}
|
|
4214
|
-
|
|
4215
|
-
|
|
5066
|
+
/**
|
|
5067
|
+
* base64 PKIX (SPKI) public key — pass this as the signer's registered
|
|
5068
|
+
* public key at agent creation / mandate approval.
|
|
5069
|
+
*/
|
|
5070
|
+
publicKeyBase64() {
|
|
5071
|
+
const der = this.publicKey.export({ format: "der", type: "spki" });
|
|
5072
|
+
return Buffer.from(der).toString("base64");
|
|
4216
5073
|
}
|
|
4217
|
-
|
|
4218
|
-
|
|
5074
|
+
/**
|
|
5075
|
+
* Returns base64( ASN.1 ECDSA signature over SHA-256(payload) ).
|
|
5076
|
+
*/
|
|
5077
|
+
sign(payload) {
|
|
5078
|
+
const signer = createSign("SHA256");
|
|
5079
|
+
signer.update(payload);
|
|
5080
|
+
const sig = signer.sign({ key: this.privateKey, dsaEncoding: "der" });
|
|
5081
|
+
return Buffer.from(sig).toString("base64");
|
|
4219
5082
|
}
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
5083
|
+
};
|
|
5084
|
+
function verifyES256Signature(publicKeyBase64, payload, signatureBase64) {
|
|
5085
|
+
let publicKey;
|
|
5086
|
+
try {
|
|
5087
|
+
publicKey = createPublicKey({
|
|
5088
|
+
key: Buffer.from(publicKeyBase64, "base64"),
|
|
5089
|
+
format: "der",
|
|
5090
|
+
type: "spki"
|
|
5091
|
+
});
|
|
5092
|
+
} catch (err) {
|
|
5093
|
+
throw new Error(`parse public key: ${err.message}`);
|
|
4223
5094
|
}
|
|
4224
|
-
if (
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
5095
|
+
if (publicKey.asymmetricKeyType !== "ec") {
|
|
5096
|
+
throw new Error("not a P-256 public key (ES256 requires P-256)");
|
|
5097
|
+
}
|
|
5098
|
+
if (publicKey.asymmetricKeyDetails?.namedCurve !== "prime256v1") {
|
|
5099
|
+
throw new Error("not a P-256 public key (ES256 requires P-256)");
|
|
5100
|
+
}
|
|
5101
|
+
const verifier = createVerify("SHA256");
|
|
5102
|
+
verifier.update(payload);
|
|
5103
|
+
const ok = verifier.verify(
|
|
5104
|
+
{ key: publicKey, dsaEncoding: "der" },
|
|
5105
|
+
Buffer.from(signatureBase64, "base64")
|
|
5106
|
+
);
|
|
5107
|
+
if (!ok) {
|
|
5108
|
+
throw new Error("signature verification failed");
|
|
4229
5109
|
}
|
|
4230
|
-
throw new TypeError(`canonical JSON: unsupported value type ${typeof value}`);
|
|
4231
5110
|
}
|
|
4232
5111
|
|
|
4233
5112
|
// src/agentic/sign.ts
|
|
@@ -4251,14 +5130,14 @@ function mandateSignPayload(mandate, action) {
|
|
|
4251
5130
|
});
|
|
4252
5131
|
return new TextEncoder().encode(encoded);
|
|
4253
5132
|
}
|
|
4254
|
-
function mandateAmendSignPayload(mandate,
|
|
5133
|
+
function mandateAmendSignPayload(mandate, version2, rule) {
|
|
4255
5134
|
if (!mandate.id) {
|
|
4256
5135
|
throw new Error("mandate has no id");
|
|
4257
5136
|
}
|
|
4258
5137
|
if (!mandate.bound_signer_id) {
|
|
4259
5138
|
throw new Error("mandate has no bound_signer_id");
|
|
4260
5139
|
}
|
|
4261
|
-
if (!Number.isInteger(
|
|
5140
|
+
if (!Number.isInteger(version2) || version2 < 2) {
|
|
4262
5141
|
throw new Error("amend version must be an integer >= 2 (the version being created)");
|
|
4263
5142
|
}
|
|
4264
5143
|
const encoded = canonicalJSON({
|
|
@@ -4268,7 +5147,7 @@ function mandateAmendSignPayload(mandate, version, rule) {
|
|
|
4268
5147
|
rule,
|
|
4269
5148
|
valid_from: mandate.valid_from ?? 0,
|
|
4270
5149
|
valid_until: mandate.valid_until ?? 0,
|
|
4271
|
-
version
|
|
5150
|
+
version: version2
|
|
4272
5151
|
});
|
|
4273
5152
|
return new TextEncoder().encode(encoded);
|
|
4274
5153
|
}
|
|
@@ -4357,86 +5236,107 @@ function addPolicyRulePayload(policyId, action, ruleType, definition, idempotenc
|
|
|
4357
5236
|
function textBytes(s) {
|
|
4358
5237
|
return new TextEncoder().encode(s);
|
|
4359
5238
|
}
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
5239
|
+
|
|
5240
|
+
// src/governance/webauthn.ts
|
|
5241
|
+
function buildChallenge(intent) {
|
|
5242
|
+
const bytes = challengeBytes(intent);
|
|
5243
|
+
const out = new ArrayBuffer(bytes.length);
|
|
5244
|
+
new Uint8Array(out).set(bytes);
|
|
5245
|
+
return out;
|
|
5246
|
+
}
|
|
5247
|
+
function challengeBytes(intent) {
|
|
5248
|
+
if (typeof intent === "string") {
|
|
5249
|
+
return utf8(intent);
|
|
4366
5250
|
}
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
*/
|
|
4370
|
-
static generate() {
|
|
4371
|
-
const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
4372
|
-
return new _P256MandateSigner(privateKey, publicKey);
|
|
5251
|
+
if (isBinary(intent)) {
|
|
5252
|
+
return toBytes(intent);
|
|
4373
5253
|
}
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
static fromPrivateKey(key) {
|
|
4379
|
-
const privateKey = typeof key === "string" || key instanceof Uint8Array ? createPrivateKey({
|
|
4380
|
-
key,
|
|
4381
|
-
format: typeof key === "string" ? "pem" : "der",
|
|
4382
|
-
type: "pkcs8"
|
|
4383
|
-
}) : key;
|
|
4384
|
-
if (privateKey.asymmetricKeyType !== "ec") {
|
|
4385
|
-
throw new Error("a P-256 private key is required (ES256)");
|
|
4386
|
-
}
|
|
4387
|
-
const details = privateKey.asymmetricKeyDetails;
|
|
4388
|
-
if (details?.namedCurve !== "prime256v1") {
|
|
4389
|
-
throw new Error("a P-256 private key is required (ES256)");
|
|
5254
|
+
if (intent && typeof intent === "object") {
|
|
5255
|
+
const canonical = intent.canonical;
|
|
5256
|
+
if (typeof canonical === "string") {
|
|
5257
|
+
return utf8(canonical);
|
|
4390
5258
|
}
|
|
4391
|
-
const publicKey = createPublicKey(privateKey);
|
|
4392
|
-
return new _P256MandateSigner(privateKey, publicKey);
|
|
4393
5259
|
}
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
5260
|
+
throw new TypeError(
|
|
5261
|
+
"expected a built intent, a prepared change, its canonical string, or its bytes"
|
|
5262
|
+
);
|
|
5263
|
+
}
|
|
5264
|
+
function isBinary(v) {
|
|
5265
|
+
return ArrayBuffer.isView(v) || Object.prototype.toString.call(v) === "[object ArrayBuffer]";
|
|
5266
|
+
}
|
|
5267
|
+
function b64urlField(name, value) {
|
|
5268
|
+
if (value === void 0 || value === null || value === "") {
|
|
5269
|
+
throw new TypeError(`passkey assertion is missing ${name}`);
|
|
4401
5270
|
}
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
*/
|
|
4405
|
-
sign(payload) {
|
|
4406
|
-
const signer = createSign("SHA256");
|
|
4407
|
-
signer.update(payload);
|
|
4408
|
-
const sig = signer.sign({ key: this.privateKey, dsaEncoding: "der" });
|
|
4409
|
-
return Buffer.from(sig).toString("base64");
|
|
5271
|
+
if (typeof value === "string") {
|
|
5272
|
+
return bytesToBase64url(base64ToBytes(value));
|
|
4410
5273
|
}
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
key: Buffer.from(publicKeyBase64, "base64"),
|
|
4417
|
-
format: "der",
|
|
4418
|
-
type: "spki"
|
|
4419
|
-
});
|
|
4420
|
-
} catch (err) {
|
|
4421
|
-
throw new Error(`parse public key: ${err.message}`);
|
|
5274
|
+
return bytesToBase64url(toBytes(value));
|
|
5275
|
+
}
|
|
5276
|
+
function packAssertion(credential) {
|
|
5277
|
+
if (!credential || credential.type !== "public-key") {
|
|
5278
|
+
throw new TypeError('expected a WebAuthn assertion with type "public-key"');
|
|
4422
5279
|
}
|
|
4423
|
-
if (
|
|
4424
|
-
throw new
|
|
5280
|
+
if (typeof credential.id !== "string" || credential.id === "") {
|
|
5281
|
+
throw new TypeError("passkey assertion is missing id");
|
|
4425
5282
|
}
|
|
4426
|
-
|
|
4427
|
-
|
|
5283
|
+
const r = credential.response;
|
|
5284
|
+
if (!r) {
|
|
5285
|
+
throw new TypeError("passkey assertion is missing response");
|
|
4428
5286
|
}
|
|
4429
|
-
const
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
)
|
|
4435
|
-
|
|
4436
|
-
|
|
5287
|
+
const response = {
|
|
5288
|
+
clientDataJSON: b64urlField("clientDataJSON", r.clientDataJSON),
|
|
5289
|
+
authenticatorData: b64urlField("authenticatorData", r.authenticatorData),
|
|
5290
|
+
signature: b64urlField("signature", r.signature)
|
|
5291
|
+
};
|
|
5292
|
+
if (r.userHandle !== void 0 && r.userHandle !== null && r.userHandle !== "") {
|
|
5293
|
+
response.userHandle = b64urlField("userHandle", r.userHandle);
|
|
5294
|
+
}
|
|
5295
|
+
const envelope = {
|
|
5296
|
+
// The verifier requires `id` to be base64url; some mobile libraries hand
|
|
5297
|
+
// out standard base64, so normalize it like the binary fields.
|
|
5298
|
+
id: b64urlField("id", credential.id),
|
|
5299
|
+
rawId: b64urlField("rawId", credential.rawId),
|
|
5300
|
+
type: "public-key",
|
|
5301
|
+
clientExtensionResults: {},
|
|
5302
|
+
response
|
|
5303
|
+
};
|
|
5304
|
+
if (credential.authenticatorAttachment) {
|
|
5305
|
+
envelope.authenticatorAttachment = credential.authenticatorAttachment;
|
|
4437
5306
|
}
|
|
5307
|
+
return bytesToBase64url(utf8(JSON.stringify(envelope)));
|
|
5308
|
+
}
|
|
5309
|
+
var MAX_PACKED_ASSERTION_LENGTH = 64 * 1024;
|
|
5310
|
+
function assertionChallengeMatches(packed, intent) {
|
|
5311
|
+
if (typeof packed !== "string" || packed.length > MAX_PACKED_ASSERTION_LENGTH) {
|
|
5312
|
+
return false;
|
|
5313
|
+
}
|
|
5314
|
+
try {
|
|
5315
|
+
const envelope = JSON.parse(new TextDecoder().decode(base64ToBytes(packed)));
|
|
5316
|
+
const clientDataB64 = envelope.response?.clientDataJSON;
|
|
5317
|
+
if (typeof clientDataB64 !== "string") {
|
|
5318
|
+
return false;
|
|
5319
|
+
}
|
|
5320
|
+
const clientData = JSON.parse(new TextDecoder().decode(base64ToBytes(clientDataB64)));
|
|
5321
|
+
if (typeof clientData.challenge !== "string") {
|
|
5322
|
+
return false;
|
|
5323
|
+
}
|
|
5324
|
+
const got = base64ToBytes(clientData.challenge);
|
|
5325
|
+
const want = new Uint8Array(buildChallenge(intent));
|
|
5326
|
+
return got.length === want.length && got.every((b, i) => b === want[i]);
|
|
5327
|
+
} catch {
|
|
5328
|
+
return false;
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
function webauthnSigner(getAssertion) {
|
|
5332
|
+
return {
|
|
5333
|
+
async sign(payload) {
|
|
5334
|
+
const credential = await getAssertion(buildChallenge(payload));
|
|
5335
|
+
return packAssertion(credential);
|
|
5336
|
+
}
|
|
5337
|
+
};
|
|
4438
5338
|
}
|
|
4439
5339
|
|
|
4440
|
-
export { APIError, AccountsResource, AgentConversation, AgenticPolicyResource, ApiKeysResource, ApplicationsResource, AuthMode, AutoTransactionsResource, ConfigurationError, CustomersResource, DEFAULT_RETRY_POLICY, DakotaClient, DestinationsResource, Environment, EventsResource, FeePayoutDestinationResource, InfoResource, InsightsResource, InstructionsResource, MandatesResource, P256MandateSigner, PaginatedIterator, PaymentAgentsResource, PoliciesResource, RecipientsResource, SandboxResource, ScheduledPaymentsResource, SelfServeResource, SignerGroupsResource, SignersResource, TransactionsResource, TransportError, UsersResource, WalletsResource, WebhooksResource, addPolicyRulePayload, attachGroupPayload, attachPolicyPayload, attachUserToWallet, canonicalJSON, consoleLogger, deletePolicyPayload, detachGroupPayload, detachPolicyPayload, detachUserFromWallet, getEnvironmentURL, mandateAmendSignPayload, mandateSignPayload, noopLogger, paginate, removePolicyRulePayload, updatePolicyRulePayload, verifyMandateSignature };
|
|
5340
|
+
export { APIError, AccountsResource, AgentConversation, AgenticPolicyResource, ApiKeysResource, ApplicationsResource, AuthMode, AutoTransactionsResource, BelowThresholdError, ConfigurationError, CustomersResource, DEFAULT_RETRY_POLICY, DakotaClient, DestinationsResource, ES256Signer, EndorsementRequiredError, Environment, EventsResource, FeePayoutDestinationResource, InfoResource, InsightsResource, InstructionsResource, InsufficientEndorsementsError, InvalidGoverningGroupError, MandatesResource, ES256Signer as P256MandateSigner, PaginatedIterator, PaymentAgentsResource, PoliciesResource, RecipientsResource, SandboxResource, ScheduledPaymentsResource, SelfServeResource, SignerGroupsResource, SignersResource, StaleSignerGroupVersionError, TransactionsResource, TransportError, UsersResource, WalletsResource, WebhooksResource, addPolicyRulePayload, addSignersToGroupIntent, assertIdempotencyKey, assertionChallengeMatches, attachGroupPayload, attachPolicyPayload, attachUserToWallet, buildChallenge, canonicalJSON, consoleLogger, createCryptoDestinationIntent, deletePolicyPayload, detachGroupPayload, detachPolicyPayload, detachUserFromWallet, getEnvironmentURL, mandateAmendSignPayload, mandateSignPayload, newIdempotencyKey, noopLogger, packAssertion, paginate, removePolicyRulePayload, removeSignersFromGroupIntent, signGovernanceIntent, updatePolicyRulePayload, updateSignerGroupGovernanceIntent, verifyES256Signature, verifyES256Signature as verifyMandateSignature, webCryptoES256Signer, webauthnSigner };
|
|
4441
5341
|
//# sourceMappingURL=index.mjs.map
|
|
4442
5342
|
//# sourceMappingURL=index.mjs.map
|