blockintel-gate-sdk 0.4.5 → 0.4.7
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.cjs +104 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -1
- package/dist/index.js.map +1 -1
- package/dist/pilot/index.cjs +72 -0
- package/dist/pilot/index.cjs.map +1 -1
- package/dist/pilot/index.js +72 -0
- package/dist/pilot/index.js.map +1 -1
- package/package.json +1 -1
package/dist/pilot/index.cjs
CHANGED
|
@@ -1186,6 +1186,12 @@ async function handleSignCommand(command, originalClient, gateClient, options) {
|
|
|
1186
1186
|
if (options.mode === "dry-run") {
|
|
1187
1187
|
return await originalClient.send(new clientKms.SignCommand(command));
|
|
1188
1188
|
}
|
|
1189
|
+
const GATEWAY_STAGES = ["HARD_KMS_GATEWAY", "HARD_GCP_GATEWAY"];
|
|
1190
|
+
const currentStage = gateClient.heartbeatManager?.getAdoptionStage?.();
|
|
1191
|
+
if (currentStage && GATEWAY_STAGES.includes(currentStage)) {
|
|
1192
|
+
emitMetric(options.metricsSink, "sign_success_total", labels);
|
|
1193
|
+
return await signViaProxy(gateClient, decision, command, signerId);
|
|
1194
|
+
}
|
|
1189
1195
|
return await originalClient.send(new clientKms.SignCommand(command));
|
|
1190
1196
|
} catch (error) {
|
|
1191
1197
|
if (error instanceof BlockIntelBlockedError) {
|
|
@@ -1199,6 +1205,72 @@ async function handleSignCommand(command, originalClient, gateClient, options) {
|
|
|
1199
1205
|
throw error;
|
|
1200
1206
|
}
|
|
1201
1207
|
}
|
|
1208
|
+
async function signViaProxy(gateClient, decision, command, signerId) {
|
|
1209
|
+
const config = gateClient.config;
|
|
1210
|
+
const baseUrl = config?.baseUrl || config?.controlPlaneUrl;
|
|
1211
|
+
const tenantId = config?.tenantId;
|
|
1212
|
+
if (!baseUrl || !tenantId) {
|
|
1213
|
+
throw new Error("[Gate SDK] Cannot use signing proxy: baseUrl or tenantId not configured on GateClient");
|
|
1214
|
+
}
|
|
1215
|
+
const message = command.input?.Message ?? command.Message;
|
|
1216
|
+
if (!message) {
|
|
1217
|
+
throw new Error("[Gate SDK] SignCommand missing Message for proxy signing");
|
|
1218
|
+
}
|
|
1219
|
+
const messageBuffer = message instanceof Buffer ? message : Buffer.from(message);
|
|
1220
|
+
const messageBase64 = messageBuffer.toString("base64");
|
|
1221
|
+
const keyId = command.input?.KeyId ?? command.KeyId;
|
|
1222
|
+
if (!keyId) {
|
|
1223
|
+
throw new Error("[Gate SDK] SignCommand missing KeyId for proxy signing");
|
|
1224
|
+
}
|
|
1225
|
+
const signingAlgorithm = command.input?.SigningAlgorithm ?? command.SigningAlgorithm ?? "ECDSA_SHA_256";
|
|
1226
|
+
const messageType = command.input?.MessageType ?? command.MessageType ?? "RAW";
|
|
1227
|
+
const proxyUrl = `${baseUrl.replace("/defense", "")}/tenants/${tenantId}/defense/sign`;
|
|
1228
|
+
const headers = {
|
|
1229
|
+
"Content-Type": "application/json"
|
|
1230
|
+
};
|
|
1231
|
+
const authHeaders = gateClient.getAuthHeaders?.();
|
|
1232
|
+
if (authHeaders) {
|
|
1233
|
+
Object.assign(headers, authHeaders);
|
|
1234
|
+
} else {
|
|
1235
|
+
const auth = config?.auth;
|
|
1236
|
+
if (auth?.mode === "api_key" && auth?.apiKey) {
|
|
1237
|
+
headers["x-api-key"] = auth.apiKey;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
const jwt = gateClient.jwt || gateClient.config?.jwt;
|
|
1241
|
+
if (jwt) {
|
|
1242
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
1243
|
+
}
|
|
1244
|
+
const response = await fetch(proxyUrl, {
|
|
1245
|
+
method: "POST",
|
|
1246
|
+
headers,
|
|
1247
|
+
body: JSON.stringify({
|
|
1248
|
+
requestId: decision.decisionId || decision.requestId,
|
|
1249
|
+
decisionToken: decision.decisionToken,
|
|
1250
|
+
keyId,
|
|
1251
|
+
message: messageBase64,
|
|
1252
|
+
signingAlgorithm,
|
|
1253
|
+
messageType
|
|
1254
|
+
})
|
|
1255
|
+
});
|
|
1256
|
+
if (!response.ok) {
|
|
1257
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
1258
|
+
const code = errorBody?.error?.code || "SIGN_PROXY_FAILED";
|
|
1259
|
+
const msg = errorBody?.error?.message || `Signing proxy returned ${response.status}`;
|
|
1260
|
+
throw new Error(`[Gate SDK] ${code}: ${msg}`);
|
|
1261
|
+
}
|
|
1262
|
+
const result = await response.json();
|
|
1263
|
+
const data = result?.data;
|
|
1264
|
+
if (!data?.signature) {
|
|
1265
|
+
throw new Error("[Gate SDK] Signing proxy returned no signature");
|
|
1266
|
+
}
|
|
1267
|
+
return {
|
|
1268
|
+
Signature: Buffer.from(data.signature, "base64"),
|
|
1269
|
+
KeyId: data.keyId || keyId,
|
|
1270
|
+
SigningAlgorithm: data.signingAlgorithm || signingAlgorithm,
|
|
1271
|
+
$metadata: { httpStatusCode: 200 }
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1202
1274
|
|
|
1203
1275
|
// src/provenance/ProvenanceProvider.ts
|
|
1204
1276
|
var ProvenanceProvider = class {
|